I have a couple of small hobby apps that were on Heroku's free tier (RIP) that I have now moved over to Fly.io. Fly.io has a migrate from Heroku process for Rails apps, but as far as I could see, not for any Ruby app. So I had to do things manually, and while deploying to Fly.io is super simple, there were a couple of small things that tripped me up that I thought I'd write about here in case any one else is also trying to deploy a Hanami 2.0 app to Fly.io.
While running through the
fly launch setup, you should get the option to setup a Postgres database. If you do, the URL will be available as an environment variable in
fly launch has completed, you should have a new
fly.toml file in the root of your project.
Before deploying your application, you'll need to make a couple of changes specific to Hanami 2.0. The
fly.toml below is where I landed in terms config for a small, simple app. The biggest changes from the generated file are as follows:
- on deploy, defines a release command to run database migrations (at the time of writing, migrations are not in Hanami 2.0 by default)
- defines the web process as
bundle exec puma -C config/puma.rb
- sets the Hanami environment
- configures the processes to run (as
["web"]) and the internal port to listen on
Once you've filled out your
fly.toml, you can run
fly deploy to send your first build to fly.io.
If you're familiar with Heroku, there's a similar build and deploy log on fly.io. Though I have found it to be not as detailed as Heroku, it has been enough to surface any config errors and correct them, so keep an eye on it as it'll surface any obvious issues.
Once your deploy is working, you likely wont need to change anything for a little while, so, if you're hosting your code on Github, you can setup an action to build and deploy on a successful build.
An example GitHub action to build and deploy a Hanami 2.0 to fly.io