Secret key base not being recognized in Production

In prod.exs I have:

config :myapp, Myapp.Web.Endpoint,
secret_key_base: System.get_env("SECRET_KEY_BASE")

But when using ./bin/myapp console in production I get the following error:
(ArgumentError) cookie store expects conn.secret_key_base to be set

Still in prod console, System.get_env("SECRET_KEY_BASE") returns the correct value, so I am not sure why I would get the error above.

Any ideas on what the problem could be?

Config is resolved during compilation, was that variable set during compilation of the app?

1 Like

@NobbZ I guess it wasn’t. I’m using a Docker container and I don’t think I specified that when I set it up.

I received a very helpful reply from @gregvaughn via Slack:

"you’re using releases? That call in prod.exs to System.get_env is happening when and where the release is built. Not on the server it is deployed on.

It’s important to understand that .exs files are not compiled and therefore have no beam files in a release. Mix manages config/*.exs and distillery converts them to another form. You can set it as “${SECRET_KEY_BASE}” and set REPLACE_OS_VARS to true in distillery to get the behavior you intend"