Deploying rails app to fly
Preface
(Skip this if you want only the commands).
Deploying rails in production mode to fly.io is little tricky with the secret credentials. Quite possible that you can run into the following errors:
Overall, setting up the secret keys and deploying to fly.io can be quite non-intuitive looking at all the tutorials as they don’t talk about it. I have summarised the steps below
Steps
Rails version: 7.0.2
Ruby version: 3.2.1
First we need the secret key for secret_key_base
; Generate a secret using
Keep this secret safe and private.
From Rails 6 multi environment credentials are supported, hence we can now go ahead and create one for production.
Generate a credential file for production
Inside that file add the keys
In rails config/environments/production.rb
do
This will make sure that the value is present.
Then do
To make sure the key is set at fly.io do
Now we can deploy the app with
If you note, I am passing it as build-arg since a command in my dockerfile requires the value. The secret added at fly is available during run time only
Updated on