Simulate config/releases.exs in dev env

Hello,

My app needs a list of credentials to access different resources: a list of auth token pairs (pairing gitlab accounts to slack accounts) with metadata (salck space, gitlab project).

We plan to write this secret configuration to a json file and put it on the server, then load it in config/releases.exs when the app boots.

My first question is : Will Jason be available when config/releases.exs is executed ? I work with people that do not know Elixir so I would avoid have them write data in .exs files If I can (not a big deal though). Actually I just need the file path in config.

Secondly, how to use this while programming . Should I just import_file my config/releases.exs inside config/dev.exs ? As config/dev.exs is compile-time, it is not equivalent, but would it work ?

Thank you

You would just put the configuration in config/dev.exs while testing locally. It should load it up just fine.

You should only put runtime configuration in config/releases.exs when using releases for deployment, no need to import it in the other config files since it’s being read by the application on start-up automatically.

Where would you actually use this file path? If you access it by Application.get_env it wouldn’t actually work since that’s being accessed on compile-time and it’ll fail if you put it in config/releases.exs.

The file path would be used at runtime by a process who would then load the file and serve its content to other processes.

Copying stuff between config files between releases is what I want to avoid. I’d rather have a single source of configuration, so we can code a feature, and let the CI deploy the app.

If you access it by Application.get_env it wouldn’t actually work since that’s being accessed on compile-time and it’ll fail if you put it in config/releases.exs .

If you access it by Application.get_env it wouldn’t actually work since that’s being accessed on compile-time and it’ll fail if you put it in config/releases.exs .

Importing releases.exs into dev.exs works actually. As mix config is also available at runtime (the vm does not stop between compiling and launching the app I guess).

I will now try to make a release to see if it works the other way around.

Thank you for your answer :slight_smile:

I’m not sure if you’ve been over this deployment documentation for Phoenix when using releases. But it states that you shouldn’t import the releases config file in the config files meant for the build step since releases.exs should only contain run-time configuration and if you do so you’ll have your runtime configuration read twice, once when building the release, and again when running it.

If you actually know the file path during the CI build step, you should put it in config/prod.exs because that’ll be read during compile-time and you don’t need to include that again in config/releases.exs.

Configuring something for compile-time vs. run-time comes down to when the information is available to the application, not when it will be used.

For example if the file path was secret and could only be retrieved when starting the application, it would have to be configured in the run-time configuration, but if it’s known before hand, it should be configured during compile-time.

Hope this helps clear things up a bit. It took me awhile to get accustomed to configuration in Elixir coming from stuff like PHP and Node.

1 Like

To be more precise, I include the release config in dev.exs but not in prod.exs, as we release with prod environment (and maybe staging or others, but not dev). This is not a phonix app but I guess we are fine with the phoenix docs then.

With this setup the path to credentials is not seen in sys.config. We need to have the json path set by system environment because we do not know it at compile time.

So it works well but I’m looking for downsides. I’d really want a fine way to have a single runtime configuration for both releases and dev.