Infrastructure Migration

Episode #374 by Teacher's Avatar David Kimura

Summary

For various reasons, we may decide to move our services off of one platform onto another. This could be due to pricing, uptime or other reasons. In this episode, we look at migrating a Ruby on Rails application and database from Heroku to Fly.
rails infrastructure database migration 14:09

Resources

Fly.io - https://fly.io/
Fly's Migrate from Heroku - https://fly.io/docs/rails/getting-started/migrate-from-heroku/

This episode is sponsored by Honeybadger

Summary

# Terminal
brew install flyctl
flyctl auth login
fly launch
fly deploy

fly open

fly logs
fly ssh console -C "/app/bin/rails console"

heroku config -s
fly secrets list
fly secrets set HEROKU_DATABASE_URL=$(heroku config:get DATABASE_URL)

heroku maintenance:on --app drexample
heroku maintenance:off --app drexample
fly ssh console

# Dockerfile
ARG NODE_VERSION=18.11.0
ARG YARN_VERSION=1.22.19

RUN curl https://get.volta.sh | bash
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:/usr/local/bin:$PATH
RUN volta install node@${NODE_VERSION} yarn@${YARN_VERSION}

# Fly Rails App Container Terminal
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null
apt update
apt install postgresql-14 -y

pg_dump -Fc --no-acl --no-owner -d $HEROKU_DATABASE_URL | pg_restore --verbose --clean --no-acl --no-owner -d $DATABASE_URL