jswny
New mix releases environment variables at runtime
Hi all! I haven’t worked with Elixir since v1.7. I was just checking out the new mix release functionality and I was thinking about how I used to work with environment variables before.
Is there a way with the new mix release process to read environment variables at runtime? Or do they still have to be populated when compiling the release? For example, I want to compile a release tarball, then send it to my remote server, then run it with a specific port specified at runtime with an environment variable.
Thanks!
Marked As Solved
hauleth
According to this part of the docs the config/releases.exs will be evaluated on each start of the release, which mean you can use System.fetch_env/1 there and it will work as expected.
Also Liked
LostKobrakai
config/releases.exs is evaluated on startup of the release.
akoutmos
If you are looking for a tutorial style application that leverages Mix releases, I put something together on my blog using Docker: https://akoutmos.com/post/multipart-docker-and-elixir-1.9-releases/
Step 2 is where I go over using a release.ex file. Hopefully that helps guide you in the right direction.
jswny
Wow that is awesome! Definitely saving this article. I use Docker to setup automatic deployments on my CI so this is going to be perfect. I have an old app setup using Distillery but I’ve been excited to get back into it and set it up with the new Mix release method.







