budgie
How can I set local defaults when local config is compile-time and production uses runtime config?
I’m trying to find out a good way to manage config in production, but the default Dockerfile from mix phx.gen.release --docker` compiles everything under /config into the release except for config/runtime.exs. For example, when I want to do this in config/config.exs:
config :app, value: “local_value”
And then this in config/runtime.exs:
config :app, value: System.get_env(“VALUE”) || raise “Message”
The problem is that it complains about how I’m trying to modify a compile-time value with a runtime one. This is a pretty standard env workflow and I’m not sure how other people are solving it.
How do you setup local defaults with runtime config in production?
Most Liked
benwilson512
With errors like this it really is helpful to copy and paste the full error as well as the full stacktrace.
LostKobrakai
You’ll generally get this error when the application config is used by Application.compile_env, which generally means the value can indeed only be changed when compiling the application and not at runtime.
But the second argument to Application.compile_env can be a key or a path (unlike Application.get_env, which only takes a key). Doing Application.compile_env(:myapp, :key) means all the config nested within :key is considered compile time required.
If only a subset of that is actually required at compile time you can do Application.compile_env(:myapp, [:key, :compile]). That would make all the configuration nested at that path compile time required but e.g. config at [:key, :runtime] would be fine. One might be doing something like compile_time_value = Application.compile_env(:myapp, :key)[:compile], which would be needlessly tainting config values as compile time required. Those should be refactored to Application.compile_env(:myapp, [:key, :compile]).








