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.

Where Next?

Popular in Questions Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
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 records...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement