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

andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Fl4m3Ph03n1x
Background This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
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
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18146 126
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
Owens
Hello all, I am developing a new mobile app with Flutter frontend and Phoenix backend. The mobile app has real-time task management and c...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Other popular topics Top

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 29377 241
New
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

We're in Beta

About us Mission Statement