nTraum

nTraum

App env specific runtime files with Releases

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

Marked As Solved

hubertlepicki

hubertlepicki

You can do if/case/switch clauses inside runtime.exs, that’s what I do.

Instead of requiring “runtime_#{app_env}.exs” you can do conditional configs inside the same file, then you don’t have to include additional runtime_XXX.exs files at all.

Also Liked

nTraum

nTraum

Yep, while not as pretty, we decided to go with the naive solution too. Thanks!

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement