RudManusachi

RudManusachi

When does runtime.exs make more sense?

What configs will make sense to put to runtime.exs?


A bit of how I configure apps:

I have generic configs in config/config.exs,
dev-specific parts are in dev.exs,
test-specific - in test.exs,
etc.

In dev.exs and test.exs I have some configs set with System.get_env/2… while for Prod environment specific configs go to releases.exs with strict System.fetch_env!/1 so application fails to start if it’s not configured explicitly, and I’m happy with it.

Looks like with runtime.exs I’ll have to use if config_env() == :prod all over the place to switch between System.get_env/2 and System.fetch_env!/1

I only see the case when System.get_env/2 is acceptable in prod as well as in dev/test then probably it would make some sense, but even then defaults for prod and dev sometimes are different.

Surely I’m missing something.

Most Liked

Eiji

Eiji

Simply:

  • releases.exs - runtime configuration for release only
  • #{Mix.env()}.exs - i.e. dev.exs, prod.exs, test.exs - those are compiletime environment-specific configuration files
  • config.exs - compiletime generic configuration file
  • releases.exs - runtime generic configuration file

Please look that machine which compiles code does not needs to run it. When calling System.get_env/1 it’s not executed in some kind of configuration queue, but immediately! This means that machine building code (regardless if it would run it or not) must have specified all environment variables.

Obviously it causes many troubles especially when same project was deployed to multiple machines when each of such machine wanted different environment configuration. It has been partially solved by releases.exs which now should be replaced by more generic runtime.exs.

I recommend to watch this video:

Nicd

Nicd

My opinion in a nutshell:

If you are on Elixir v1.11, use config/runtime.exs for all configuration by default. Make files like config/runtime_dev.exs as needed and use config_env/0 to check which one to import. (EDIT: Turns out config/runtime.exs doesn’t support imports.) Only move configuration to config/config.exs that you know that you need to set at compile time.

This should give you the easiest path forward as your configuration will behave the same way in dev, test, prod, and release by default.

LostKobrakai

LostKobrakai

The problem is knowing which files need copying. Unless imported files can be statically determined at buildtime the release won‘t be able to know which config files to include additionally.

Where Next?

Popular in Discussions Top

jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
laiboonh
Hi all, I am trying to convince my team to use liveview over the current react. What are some of the points where one should consider us...
New
pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New
hazardfn
I suppose this question is effectively hackney vs. ibrowse but we are at a point in our project where we have to make a choice between th...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
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
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement