I have a Phoenix application that is happily using runtime.exs to configure settings at runtime. The Phoenix app is deployed via a Dockerfile and a mix release.
In that phoenix application we set our own app_env config setting to distinguish between staging / prod / demo environment settings. The file has been growing steadily, so I’d like to introduce app-env specific runtime config files, similar to what mix does with compile-time settings.
My runtime.exs therefore contains generic configuration that is applicable to all envs - and at the very bottom:
# runtime.exs
# [... generic config here] ...
# Import app env specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
runtime_file = "runtime_#{app_env}.exs"
IO.puts("Requiring #{runtime_file}")
Code.require_file(runtime_file, __DIR__)
With my config dir looking like this:
$ tree config/
config/
├── config.exs
├── dev.exs
├── prod.exs
├── runtime_dev.exs
├── runtime.exs
├── runtime_prod.exs
├── runtime_staging.exs
├── runtime_test.exs
└── test.exs
This works well locally and on CI, but inside the Dockerfile the application is packaged and run via mix release. When starting the app, it rightfully complains that it cannot find config/runtime_prod.exs anymore.
Is there a way I can have these app-env specific runtime files while using mix releases? Looking at my Dockerfile, nothing special is happening with the default runtime.exs, it’s simply copied over:
# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
COPY rel rel
RUN mix sentry.package_source_code
RUN mix release
My attempt to include the other runtime config files via wildcard does not work:
# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime*.exs config/
COPY rel rel
RUN mix sentry.package_source_code
RUN mix release






















