fxn
How to avoid duplicated build time vs releases configuration
(I have found some threads in the forum that in one way or another touch this topic, but none of them solves this question in a clear way.)
As you know, build time configuration is located in config/config.exs, Mix uses that file to generate the application resource file, which contains the hard-coded application environment, among other things.
On the other hand, we have now config/releases.exs, which is evaluated at runtime, but only for releases.
Now, in my project everything is set via system environment variables regardless of the type of server. So, for example I have
config :avrora, registry_url: System.fetch_env!("AVRO_REGISTRY_URL")
and a dozen others like that.
Is it correct that despite the intended uniformity, I have to repeat that line in config/config.exs and in config/releases.exs?
Is there a way to avoid that duplication? I was thinking about creating config/common.exs, to be imported in both files, but the docs for mix release say you cannot use import_file (does it mean import_config?).
Most Liked
josevalim
Exactly. There is a gap between config/config.exs and config/releases.exs, because one is compile-time and the other is runtime. That’s why it has been historically awkward to do runtime configuration for Mix. config/releases.exs solves it, but only for releases. We are aware of the issue and we have a proposal in draft, to be included on v1.11, that makes it clear what is compile-time and what is runtime. This should be the last stop in our journey to improve Elixir configs that started back in v1.9.
josevalim
It is still in draft. It should be published in the upcoming week.
keathley
I’m the author of Vapor so obviously I’m biased. But my preference is to completely avoid all of the config/**.exs files for runtime configuration. Its way more trouble then its worth. Vapor is a formalization of the patterns that I’ve been using to manage configuration values in the services I maintain. The library itself has gone through a few different iterations but overall its been useful.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








