Deployments

Deploying applications to Fly can be as simple as running:

fly deploy

When the application successfully deploys, you can quickly open it in the browser by running:

fly apps open

If all goes well, you should see a running application in your web browser. You can also view a history of deployments by running:

fly releases
VERSION STABLE  TYPE  STATUS    DESCRIPTION                             USER                  DATE
v55     true    scale succeeded Scale VM count: ["web, 6"]              brad@fly.io           2022-08-10T17:05:57Z
v54     true    scale dead      Scale VM count: ["web, 0"]              brad@fly.io           2022-08-10T16:43:13Z
v53     true    scale succeeded Scale VM count: ["web, 6"]              brad@fly.io           2022-08-10T16:42:51Z
v52     true    scale succeeded Scale VM count: ["web, 6"]              brad@fly.io           2022-08-10T16:40:57Z
v51     true    scale succeeded Scale VM count: ["web, 3"]              kurt@fly.io           2022-08-08T20:14:08Z
v50     true    scale succeeded Scale VM count: ["web, 3"]              kurt@fly.io           2022-08-08T19:55:23Z

Troubleshooting a deployment

If a deployment fails, you’ll see an error message in the console. If the error is a Rails stack trace, it will be truncated. To view the entire error message run:

fly logs

You may need to open another terminal window and deploy again while running fly logs to see the full error message.

Running migrations

Migrations are configured to automatically run after each deployment via the following task in your application’s lib/tasks/fly.rake file:

task :release => 'db:migrate'

To disable automatic migrations for deploys, remove the dependency from the :release task. Then, to manually run migrations after a deployment, run:

fly ssh console -C "/rails/bin/rails db:migrate"

Run ad-hoc tasks after deploying

Sometimes after a deployment you’ll need to run a script or migration in production. That can be accomplished with the Fly SSH console by running:

fly ssh console
Connecting to top1.nearest.of.my-rails-app.internal... complete
cd app
ls
Aptfile       CHANGELOG.md  Dockerfile    LICENSE     README.md  app   config.ru  fly     package.json       pull_request_template.md  test    yarn.lock
Brewfile      CODE_OF_CONDUCT.md  Gemfile       Procfile      Rakefile   bin   db     lib     postcss.config.js  resources           tmp
Brewfile.lock.json  CONTRIBUTING.md Gemfile.lock  Procfile.dev  SECURITY.md  config  docs     node_modules  public       tailwind.config.js        vendor
bundle exec ruby my-hello-world-script.rb
hello world

Asset compilation and build commands

The default Rails image is configured to run assets:precompile in your application’s lib/tasks/fly.rake file:

task :build => 'assets:precompile'

If you have additional build steps beyond the Rails asset precompiler, you may need to modify your application’s lib/tasks/fly.rake file.