Best practice regarding configuration files for an app (iex -S mix & mix release)

Hello everyone ! :wave:

I’m new to the forum, even if I used it a lot when learning Elixir I never had the need to ask my own questions. I always found my answers there but not this time. That’s why I’m writing my first post :smile:

Here is the context: I have an Elixir application that I have always used by launching it via the command iex -S mix phx.server.

This app is an Umbrella app. Until now I had shared the configuration files between the different apps.

Recently I wanted to try switching to mix release with the Docker option. I had a lot of modifications to make but I finally managed to get my app working. I just have a few libraries that don’t work correctly because they use things not allowed in mix release but these are for “bonus” uses, let’s say.

However, I am not satisfied at the moment with what I have done. I copied/pasted all the contents of my config.exs, prod.exs and prod.secret.exs files into the runtime file. Then in my Dockerfile I copied only this file with a custom config.exs file which contains very little config.

My runtime file is currently 1500 lines long because it contains the configs of all my applications.

Is there another way to do it that is cleaner?

In fact I would like to be able to make my code coexist so that it is able to run my application both with iex -S mix and mix release.

What are the best practices regarding configs for an Umbrella application that must be able to work in both modes?

I’ve read a lot of different things about this, some delete app config files, others keep them so I’m not sure what the best method is.

NB: If I copy all my config files in the Dockerfile I need a ton of environment variables that are not accessible at build time (and therefore require the use of a secret file). This is why I created a configs file which only contains the minimum for compilation and which is only used for the mix release.

I thank all the people who will answer me and those who have already given me so many answers in the past :pray:

The questions to ask yourself are:

  1. Does it need to be in the Application config?
  2. Is the config different depending on the environment?
  3. Does it need to come from runtime envs?

Sorry for a non-answer :slight_smile:

Can you give us a couple of examples for the configs, and we can talk about some options for them?

1 Like

These are indeed good questions that I could ask myself.

But for example:
Some people on the team put in the prod.secret.exs file configs containing values ​​that are supposed to be secret. However, these values ​​are actually retrieved from environment variables. So is it really useful to have a prod.secret.exs file in this case? Is there a benefit?

Then actually our production and development/test configs are indeed different. But is it a good practice to do it like this?

For example: Ecto configs, for dev/test they are written directly in the code, while in prod the values ​​are retrieved from env variables. But isn’t it better to only have one config in the root configuration which would read the values ​​via environment variables?

Or in dev/test algorithms used are less “heavy” than those used in production so the configurations are different. Is it not better to just have if test do this in the config file ? I’m just asking to be sure, I’m not saying this or that way is better.

Finally about the config per application in the case of our Umbrella app all applications must be launched/used. Hence my question regarding having config per application. Is it useful ? Is it better to separate them, to group them together at the root? If I specify a config for an application this configuration will be propagated to all the other apps anyway, right?

Anyway, thank you for your answer :smiley:

1 Like