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

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement