Docker release question: should config.exs be getting called?

I have a docker release of a phoenix+elixir app that I am deploying.
Deployment seemed to be working, but I discovered that some environment variables were not being read.
I tracked this down to the config settings in config.exs not being processed.
To verify this, I added a log statement at the top of config.exs. When I run locally it prints to the console. When I run in docker it does not print to the docker log.
both runtime.exs and prod.exs have an import Config as the first line.

This may just my lack of understanding of the execution sequence on a release, but shouldn’t the config.exs be getting processed when I run /app/bin/server ?

Does anyone have suggestions of things to check or ways to further debug why the routines in config.exs not getting executed when starting the release build?

config.exs is always read and evaluated at compile-time.

Since you want to load config after application has been compiled, you need to use runtime.exs configuration, you can read more about this here: Configuration and releases - The Elixir programming language

1 Like

Awesome. That worked. I appreciate you pointing me to the documentation, too. Thanks!

Here’s what I don’t understand. What mechanism keeps Config.exs from being processed at runtime, since it is imported into runtime.exs? Are there some conventions and rules specially around how Config.exs is processed, even if it is included in runtime.exs?

Showing my lack of knowledge, just looking at the code, with runtime.exs having import Config I expected the code in Config.exs would have been processed in runtime.exs. How am I thinking about this incorrectly?

If you are just getting started I would recommend to not give much thought about it.

Config works like this because there is compilation-time magic involved (metaprogramming) in the language.

The only thing you need to know is that all values from config.exs are evaluated when the project is compiled, this is why doing something like ENV_VAR=test mix compile will work on your local env but never in a release.

1 Like

config.exs is a script file. It is not a module called Config. Filenames have no influence on module names.

Modules are defined with defmodule Config do ... end and you can put multiple modules in a file. You can even best modules inside others.

1 Like

Thank you @cmo and @D4no0 for the replies and details.
Your info helps a lot. I appreciate you taking the time to provide more explanation and more pointers to the right parts of the docs.

1 Like