Hey, this fortunately has a simple solution.
The problem occurs because asset compilation will load your initialiser, and RAILS_MASTER_KEY
is only available at runtime. ENV
in the Dockerfile is only available at runtime. Locally it probably works because you have your master.key
file on the filesystem.
A quick way to fix this would be to pass RAILS_MASTER_KEY
as a build argument like:
fly deploy --remote-only --build-arg RAILS_MASTER_KEY=$(cat config/master.key)
That’s not ideal, though, as build arguments are stored in image history, unnecessarily exposing your credentials.
The correct way to make this work is to ensure that you initialiser is not run unless you need it in during asset compilation. You could do this by changing the asset compilation line to RUN bundle exec rails assets:precompile ASSET_COMPILE=1
, then conditionally checking for ENV['ASSET_COMPILE']
in your initialiser(s).