What is the suggested way of supplying system environment variables to application built with mix release
and using runtime.exs
for configuration? .env
type of approach doesn’t seem to be en vogue among Elixir folks, does it?
Depends on how things are run. Most ways of running a release (in prod) also have a way of providing system env variables to that binary.
I’d assume (still deciding though) it’d be run from systemd
as one of the “services”, unless there are some other well proven deployment patterns for doing this. I am somewhat reluctant with this approach. Would like things to be “contained”. So maybe I should rephrase the question to “what is the suggested method of running the application”
In a systemd system the service is the unit of containment.
I know. It’s probably that I am yet to fall in love with systemd
and trying to find how you guys run your phx applications, hoping that maybe you do it differently
For a hobby project that I run via systemd I use a EnvironmentFile
directive to specify the file that has the environment variables and read the values in config/runtime.exs
. I also use the wonderful systemd | Hex package by @hauleth. My setup feels pretty contained to me because everything is effectively within that single directory. Of course the systemd file is installed into /etc
but I keep a copy of it in the repository as well.
Some datapoints from my projects:
- Gigalixir - use gigalixir’s UI
- AWS ECS - use task definitions
- Self-hosted with docker: use docker-compose with a .env file