Web Development / 09 February 2024 / by Guillermo Díaz

Deploying a Ruby on Rails Application on Fly.io

This guide outlines the steps to deploy a Ruby on Rails application on Fly.io, including environment variable setup, scaling, and management commands.

Prerequisites

  • Ruby on Rails application ready for deployment.
  • Fly.io account.
  • Homebrew (for macOS users).

Steps

Install Fly.io CLI

Install the Fly.io Command Line Interface (CLI) using Homebrew:

brew install flyctl

Authenticate with Fly.io

Log in to Fly.io:

fly auth login

Initialize the Deployment

From your project directory:

flyctl launch

During this, you’ll:

  • Select a name for your application.
  • Choose a deployment region.
  • Decide on attaching a Postgresql database.

Configuration and Dockerfile Creation

The flyctl launch command generates:

Dockerfile .dockerignore bin/docker-entrypoint config/initializers/sentry.rb config/dockerfile.yml fly.toml (and validates it)

Set Environment Variables

fly secrets set YOUR_ENV_VARIABLE="value"

Redeploy Application

After setting the environment variables, redeploy your application:

fly deploy

Working with Rails Console

To interact with the Rails console:

fly console

Checking Server Specifications

To view current server specifications like memory and processor:

fly scale show

Scaling the Application

To scale up memory:

fly scale memory 512 # or 1024, as needed

To scale down and reduce costs:

fly scale memory 256

Restarting the Application

Restart your application instance:

fly apps restart <your-app-name>

Documentation

For specific requirements or troubleshooting, the Fly.io documentation is pretty useful.

Tags: