Proper way to have a local, non-commitable addition to runtime.exs

This is related to this Runtime configuration only for production , but specifically the part about replacing dev.exs / dev.local.exs with a runtime.exs file.

This has probably been discussed already, but I could not find the conclusion, sorry in advance.

The Config documentation hints that runtime.exs should be organized like this:

# runtime.exs
import Config

# SiteCC

case config_env() do
   :dev ->
       # config for developper machines
   :test ->
       #  config for mix tests
   :prod ->
       # config for production 
end

However, a common situation is that the configuration for a specific developer might (maybe temporarily) differ from the configuration of other members of the team (feature flags, per-developper secrets, etc…)

It’s entirely possible to handle that by having the code use environment variables instead of (or in addition to) the runtime.exs configuration ; each developer has to source environment variables, possibly from a .env.local file that is .gitignore-ed.

However, previously, it was possible to add a couple of lines to a dev.exs file in the spirit of:

# dev.exs

## ...Common developers configuration...

if File.exists?("dev.local.exs") do
    import_config("dev.local.exs)
end

And then a dev.local.exs file is defined, and it’s added to .gitignore, and developers have a safe sandbox.

Naively doing it with runtime.exs fails, because runtime.exs does not allow importing other files.

So is there a “cleaner” way to do this ?

2 Likes

If that works, why change it? I personally don’t see much reason for using runtime.exs for :dev besides if system env variables should be supported.

3 Likes