Library or best practise for complex runtime configuration when using `mix release`?

I’m working towards deploying my first Phoenix app to production, and I’m trying to find a good way to add more complex run-time configuration to my app (it’s built with mix release, so there’s no config.exs that can be edited on the deployment server).

Environment variables work great for scalar values, but I need an environment-specific structure like this passed into my app

config :app, :dns
  servers: [
    %{
      hostname: "ns1.example.org",
      region: "east",
      type: :bind
    },
    %{
      hostname: "ns2.example.net",
      region: "west",
      type: :nsd4
    }
  ]

One approach would be to compile it to JSON and then stuff this JSON into an environment variable, and then read the env-var and parse the JSON in releases.exs, but that is not exactly elegant. Any suggestions for a better way to accomplish this?

1 Like

It sounds like what you are looking for are Config providers https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-config-providers

If JSON is your format of choice the sample JSONConfigProvider here https://hexdocs.pm/elixir/Config.Provider.html will be a good starting point for you. Hope that helps!

3 Likes