2

I'm trying to deploy a rails 7 app to Fly.io, which uses Docker to deploy apps. I keep getting the below error when I try to deploy.

ActiveSupport::EncryptedFile::MissingKeyError: Missing encryption key to decrypt file with. Ask your team for your master key and write it to /app/config/credentials/production.key or put it in the ENV['RAILS_MASTER_KEY'].

I've tried putting the following into my docker file:

RUN --mount=type=secret,id=RAILS_MASTER_KEY \
RAILS_MASTER_KEY="$(cat /run/secrets/RAILS_MASTER_KEY)" 

Then running:

fly deploy \
--build-secret RAILS_MASTER_KEY=the_actual_secret_key_here

That doesn't work. I've added the key as an environment variable to fly.io, but my understanding is this is failing because production keys aren't available at build time. Anyway, I'm stumped. Any ideas?

I'm new to docker, so it's likely I'm just missing something simple here.

Arel
  • 3,888
  • 6
  • 37
  • 91

1 Answers1

1

I know I'm late to this. But I had similar issue today. I was able to make it to work by the following:

deleting the master.key

creating a new one by running

EDITOR="code --wait" bin/rails credentials:edit

add the necessary keys, e.g cloudlflare, aws etc.

re-run fly deploy

Credits: https://github.com/mrsked/mrsk/dis

Marvin
  • 11
  • 4
  • I believe the Github link you provided is supposed to give more context/reference to your answer, but it doesn't lead to any valid Github repository and you check and edit this. – MartinsOnuoha Jul 11 '23 at 18:53