Add support for RAILS_MASTER_KEY in Auto DevOps build stage
Description
I'm trying to build my Rails 5.2 app using Auto DevOps, but the build phase crapped out while building the container. My Dockerfile needs a missing config/master.key
or RAILS_MASTER_KEY
environment variable in order to precompile assets.
Step 15/16 : RUN if [[ "$RAILS_ENV" == "production" ]]; then rails assets:precompile; fi
---> Running in edf7441b985d
Missing encryption key to decrypt file with. Ask your team for your master key and write it to /usr/src/app/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
I can't check master.key
into the repo for security. I tried setting a secret variable RAILS_MASTER_KEY
but it's not being passed into the docker daemon during build.
A workaround is to inject the variable into .gitlab-ci.yml with
echo "$RAILS_MASTER_KEY" > config/master.key
But I hope Auto DevOps supports this scenario without the need to customize Auto-DevOps.gitlab-ci.yml
Proposal
I'm not sure what's the optimal way to do this. Injecting master.key
in .gitlab-ci.yml doesn't seem like a good idea since it'll unnecessary introduce Rails-specific feature. Perhaps updating .gitlab-ci.yml to propagate the secret variable into docker build daemon with docker build --build-arg var_name ...
might be another option.