I got this question awhile ago and answered in Gist form. I recently stumbled on my answer and thought it was worth sharing, so here you go:


On Heroku compiles are run without environment variables. Why?

If you compile the same source code you will get the exact same compiled app output every time.

This is determinism. The app build is deterministic.

If you allow environment variables at build time, the output of the app is no-longer deterministic based solely on the code. You can deploy the same code and get different results.

If you are using user-env-compile your app builds are now non-deterministic.

Why is this bad?

It is harder to troubleshoot and reproduce problems. It means if you change your config, you technically need to recompile your app every time.

Add-on providers are allowed to change your environment variables (vendor prefixed for safety). But changing the variable does not trigger a new deploy. If you’re app doesn’t need user env compile this isn’t a problem. Otherwise who knows.

Not only are you enabling your Heroku config to be available at compile/build/deploy time, you could be affecting internal environment variables as well like $PATH or $GEM_HOME, and if you mess those up, there isn’t much we can do to fix them.

In short: Best practice is to not use user-env-compile.