budgie

budgie

How can I set local defaults when local config is compile-time and production uses runtime config?

I’m trying to find out a good way to manage config in production, but the default Dockerfile from mix phx.gen.release --docker` compiles everything under /config into the release except for config/runtime.exs. For example, when I want to do this in config/config.exs:

config :app, value: “local_value”

And then this in config/runtime.exs:

config :app, value: System.get_env(“VALUE”) || raise “Message”

The problem is that it complains about how I’m trying to modify a compile-time value with a runtime one. This is a pretty standard env workflow and I’m not sure how other people are solving it.

How do you setup local defaults with runtime config in production?

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

With errors like this it really is helpful to copy and paste the full error as well as the full stacktrace.

LostKobrakai

LostKobrakai

You’ll generally get this error when the application config is used by Application.compile_env, which generally means the value can indeed only be changed when compiling the application and not at runtime.

But the second argument to Application.compile_env can be a key or a path (unlike Application.get_env, which only takes a key). Doing Application.compile_env(:myapp, :key) means all the config nested within :key is considered compile time required.

If only a subset of that is actually required at compile time you can do Application.compile_env(:myapp, [:key, :compile]). That would make all the configuration nested at that path compile time required but e.g. config at [:key, :runtime] would be fine. One might be doing something like compile_time_value = Application.compile_env(:myapp, :key)[:compile], which would be needlessly tainting config values as compile time required. Those should be refactored to Application.compile_env(:myapp, [:key, :compile]).

D4no0

D4no0

A word of advice is to use credo, it will always warn you about defining compile-time config incorrectly in your code, and in general is a must-have tool for your elixir codebase, especially if you are new to the ecosystem.

richgal

richgal

This article helped me a lot to understand environment handling.

https://www.theerlangelist.com/article/rethinking_app_env

Where Next?

Popular in Questions Top

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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
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
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement