Learning to Fly... with Fly.io

Deploying a Rails app

I’ve historically always reached for Heroku to deploy little apps and side projects when I wanted to push them out for others to see and use. When Heroku ended their “free” plan, several new platforms seemed to emerge or old alternatives gained renewed interest, such as render, hatchbox, fly, digital ocean and many others. In this post I’m going to focus on Fly.io which I’ve used a couple of times and been very impressed with.

What is Fly?

Fly is a platform that lets you very simply deploy full stack apps and databases to their globally distributed network, with the minimum of fuss. If you have a Rails app running on your local machine, you can get it deployed and available to users all over the world in literally minutes!

Fly.io

Install Fly on MacOS

First things first, we need to install the Fly app locally. I use Homebrew to manage all package installs on my Mac, and I recommend you do too if you don’t already.

brew install flyctl

If this is your first time using Fly, then you’re going to need an account there too which can be set up for free as follows. Note you will need to provide a credit card, but you won’t incur any charges for a simple app.

fly auth signup

If you already had an account, you’ll need to sign in

fly auth login

Deploy your app

Now you’re ready to deploy and launch your Rails app! In my case the app is named example - obviously use your app name here in place of ‘example’ - so cd into the root directory of the app, and start the Fly launch wizard!

cd example
fly launch

When you run the launch command the first time, you’ll run through a few questions in the terminal. Firstly you need to choose a name, or accept the default, then select a region to deploy to. In my case I chose London.

Creating app in ~/example
Scanning source code
Detected a Rails app
? Choose an app name (leave blank to generate one): example
automatically selected personal organization: Your Name
Some regions require a paid plan (bom, fra, maa).
See https://fly.io/plans to set up a plan.

? Choose a region for deployment:  [Use arrows to move, type to filter]
  Guadalajara, Mexico (gdl)
  Rio de Janeiro, Brazil (gig)
  Sao Paulo, Brazil (gru)
  Hong Kong, Hong Kong (hkg)
  Ashburn, Virginia (US) (iad)
  Johannesburg, South Africa (jnb)
  Los Angeles, California (US) (lax)
> London, United Kingdom (lhr)
  Madrid, Spain (mad)
  Miami, Florida (US) (mia)
  Tokyo, Japan (nrt)
  Chicago, Illinois (US) (ord)
  Bucharest, Romania (otp)
  Phoenix, Arizona (US) (phx)
  Querétaro, Mexico (qro)

Then you’ll be asked if you want to provision a database (yes) and a redis instance (probably not yet) and you’ll see lots of output as a docker image is created and deployed.

After a few minutes you should see the process complete. You will also see a few files were generated fly.toml, Dockerfile, .dockerignore etc. These are generated once and once complete you’re ready to deploy!

fly deploy

This will take a couple of minutes and all being well you’ll be shown a URL where you can visit your app online!

As you work on your webapp, you just need to fly deploy to push the latest out live!

There are lots of further options, capabilities and features, all covered in the excellent Fly Documentation but I hope this quick intro has given you the basics and got you up and running!