This post is proudly sponsored by Code & Co. Disclaimer: I’m not affiliated to fly.io at all, this is just a personal account of my experience with it. Fly.io 101 Even though fly is pretty much “Phoenix First” these days (they hired Chris McCord for a reason!), it’s still a very decent way to deploy a Reactive Rails app, as Matt Yorkley has demonstrated here. Let’s go through a quick list of preliminary information before we get started. Docker or Buildpacks? A lot of Rails developers considering Fly as a Platform as a Service these days are accustomed to the Heroku way of deploying apps via git push and Cloud Native Buildpacks that manage the deployment process automatically. While Fly defaults to a Dockerfile builder - and indeed, the Rails setup wizard will generate one for you, as we shall see - you can also use a buildpack builder by specifying a builder and buildpacks in the fly.toml configuration: [build] builder = "heroku/buildpacks:18" buildpacks = ["...", "..."] Also refer to this blog post to select the correct builder (at the moment of writing this would be heroku/buildpacks:18) Free Allowances While Fly has a quite generous stack of free allowances which will let you start and maintain a reasonably sized side-project for free, I would like to specifically point out their free postgres offering, which largely builds on the allowed 3GB of volume storage. Here are a few examples for how to configure it. Bear in mind though that the free compute allowance is summed together for all apps - if you exceed that, you might not be able to keep your whole Rails project free. Getting Started The first thing you’ll want to do, is to install the flyctl CLI (see here) Next, quite obviously, you need to create a Fly account. Run flyctl auth signup, which will in turn open the browser for you. Note that you will have to provide credit card information upfront, because ”here’s what happens if you give people freemium full access to a hosting platform: lots and lots of free VMs mining for cryptocurrencies.” Fair enough from my vantage point. Run flyctl auth login to authenticate against Fly. Now you’re all set up to deploy your first app. Setup Wizard For the remainder of this walkthrough, let’s assume you have a simple Rails app called my-app, and your terminal’s working directory is pointing to the root folder of this app. I’ll start this by a rundown of the official Rails Getting Started tutorial, before I dive into a little more advanced topics. The setup wizard for Rails apps is suprisingly helpful. If you run fly launch it will: Detect a Rails app Ask you to specify your organization and primary region Produce a fly.toml file, which we will look at later Ask whether you would like to set up a Postgresql database right now. If you do that, it will save you the effort of creating and attaching to it manually. This is eminently helpful because it sets up the DATABASE_URL via an application secret right away. It then rattles through the process of preparing your app for deployment. Notice that it is not yet deployed at this stage! Below is a sample output of that command: $ fly launch Creating app in /..... Scanning source code Detected a Rails app ? App Name (leave blank to use an auto-generated name): my-app
DevOps
Ruby on Rails
Added: 10 Oct 2022