Distillery 2 / Docker - Runtime different parameters with the same prod release

Well according to Twelve factor App, you should really have one release application, and by one I mean, one codebase/compiled/bundled app (probably with distillery and mix release), while “environment” specific stuff should be config provided via ENV vars or config files (with sane defaults) that application loads at start.

If you choose ENV vars, and if you use distillery >= 2.0.0 for release, you could easily read ENV at runtime with distillery plugin called config tuple.

Finally, your code looks like
config/config.exs:

config :api_search,
   :elastic,
   elastic_url:
     {:system, "ELASTIC_URL", "elasticsearch-client.elasticsearch.svc.cluster.local"}

usage somewhere in lib/application.ex:

...
env = Application.get_all_env(:api_search)
elastic_url = env[:elastic][:elastic_url]
...

If you succeed this, since you’ve mentioned docker in title, you have one release binaries and you’re making one docker image that could be run everywhere (staging, qa, prod, etc…).

1 Like