Hmm … I might be able to do this if I restructure my production.rband initializers. They need access to secrets which I don’t commit to the repo. Like SMTP config.
I could add an ENV var to the rake file signaling e.g. not to set up SMTP because it’s only the build stage…
I got around this problem by using Rails credentials and feeding the builder the RAILS_MASTER_KEY. It was a pretty big restructure but we found it ended up being simpler to maintain. YMMV
The builder won’t have the secrets as ENV variables by default. But if you have an ENV file (.env) or something like that, you most definitely can read it from within the builder. That was our workaround for a small amount of time but it’s definitely not ideal; that’s what pushed us to switch to Rails credentials.
Needing to fake out rails during a docker build is a pretty common thing, and moreover, you probably don’t want secrets avail in your docker build environment. I tend to just set fake values for docker build and then set the real ones at runtime. So, typically you’ll end up with lines like this in your Dockerfile:
Yea, in general it’s probably a better way to go. It’s good to imaging your build environments as ephemeral, eg not places where you should need to have secrets present.