Existing Elixir Apps

If you have an existing Elixir app that you want to move over to Fly, this guide walks you through the initial deployment process and shows you techniques you can use to troubleshoot issues you may encounter in a new environment.

Provision Elixir and Postgres Servers

To configure and launch your Elixir app, you can use fly launch and follow the wizard.

When we run fly launch from the newly-created project directory, the launcher will:

  • Ask you to select a deployment region
  • Set secrets required by Phoenix (SECRET_KEY_BASE, for example)
  • Run the Phoenix deployment setup task
  • Optionally setup a Postgres instance in your selected region
  • Deploy the application in your selected region
cd <app_name>
fly launch
Creating app in /Users/me/<app_name>
Scanning source code
Detected a Phoenix app
? App Name (leave blank to use an auto-generated name): <app_name>
? Select organization: flyio (flyio)
? Select region: mad (Madrid, Spain)
Created app <app_name> in organization soupedup
Set secrets on <app_name>: SECRET_KEY_BASE
Installing dependencies
Running Docker release generator
Wrote config file fly.toml
? Would you like to setup a Postgres database now? Yes
Postgres cluster <app_name>-db created
  Username:    postgres
  Password:    <password>
  Hostname:    &lt;app_name&gt;-db.internal
  Proxy Port:  5432
  PG Port: 5433
Save your credentials in a secure place, you will not be able to see them again!

Monitoring Deployment

1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 2 total, 2 passing]
--> v0 deployed successfully

Connect to postgres
Any app within the flyio organization can connect to postgres using the above credentials and the hostname "&lt;app_name&gt;-db.internal."
For example: postgres://postgres:password@&lt;app_name&gt;-db.internal:5432

See the postgres docs for more information on next steps, managing postgres, connecting from outside fly:  https://fly.io/docs/reference/postgres/
Postgres cluster &lt;app_name&gt;-db is now attached to &lt;app_name&gt;

Would you like to deploy now? Yes
Deploying &lt;app_name&gt;

==> Validating app configuration
--> Validating app configuration done
TCP 80/443 ⇢ 8080
Remote builder fly-builder-little-glitter-8329 ready

That’s it! Run fly apps open to see your deployed app in action.

Try a few other commands:

  • fly logs - Tail your application logs
  • fly status - App deployment details
  • fly status -a &lt;app_name&gt;-db - Database deployment details
  • fly deploy - Deploy the application after making changes

You can set a name for the app, choose a default region, and choose to launch and attach a PostgreSQL database.

Deploy your application

Deploying your application is done with the following command:

fly deploy

This will take a few seconds as it uploads your application, builds a machine image, deploys the images, and then monitors to ensure it starts successfully. Once complete visit your app with the following command:

fly apps open

If all went well, you’ll see your Elixir application homepage.

Troubleshooting your initial deployment

Since this is an existing Elixir app, its highly likely it might not boot because you probably need to configure secrets or other service dependencies. Let’s walk through how to troubleshoot these issues so you can get your app running.

View log files

If your application didn’t boot on the first deploy, run fly logs to see what’s going on.

fly logs

This shows the past few log file entries and tails your production log files.

Open an IEx Session

It can be helpful to open a IEx Session to run commands and diagnose production issues.

To do this, we will login with SSH to our application VM. There is a one-time setup task for using SSH. Follow the instructions.

fly ssh issue --agent

With SSH configured, let’s open a console.

fly ssh console --pty -C "/app/bin/hello_elixir remote"
Connecting to hello_elixir.internal... complete
Erlang/OTP 23 [erts-11.2.1] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]

Interactive Elixir (1.11.2) - press Ctrl+C to exit (type h() ENTER for help)

You have a live IEx shell into your application!