fireproofsocks

fireproofsocks

Gigalixir ENV variables not accessable

I’ve been deploying an umbrella app to a Gigalixir instance and mostly it’s been working beautifully. I’ve probably got something misconfigured, but some of the ENV vars are not available at runtime – I did use gigalixir config:set IMPORTANT_URL=foo and I do see the expected values when I run gigalixir config.

However, I’m seeing stuff like "Querying ${IMPORTANT_URL}" in the logs. I did restart the service, but I’m still getting this errors because of this. I confirmed that once I hard-coded the values in my config file (with the values visible from gigalixir config, the errors stopped (!?!?!)

Is there something else we need to be doing when adding ENV vars to our Gigalixir deployments?

Many thanks!

Most Liked

jola

jola

Maybe if you show us some more code. Could you show the code where you read the config? Note that if you would eg get the config value in a module attribute that would happen at compile time and not reflect the run time value.

@important_url Application.get_env(:my_app, :important_url) would not correctly get the run time value of the environment, it would capture what the config value was at compile time (which is "${IMPORTANT_URL}".

NobbZ

NobbZ

This is only half of the truth.

It is perfectly fine to use System.get_env in your code, whether you use distillery or mix based deployments.

You have to be careful though when you use environment variables in the config/*.exs files, they will only be evaluated at “mix-time”.

Similar caution has to be taken when reading environment variables in module attributes, but REPLACE_OS_VARS wouldn’t help there either, as distillery only hooks into the application environment at the applications boot IIRC.

jola

jola

EDIT: Originally gave a short answer but I see it was easily misunderstood, so giving a longer answer instead.

If you’re deploying with mix you don’t have access to those magic ${VAR} string replacements. Instead, you’ll want to grab stuff from env by using System.get_env. Since config is evaluated at runtime it will read the system env when you run your app, so you have the same behavior between calling System.get_env in some function and in your config.

If you’re doing Distillery releases things are a bit different. The config is evaluated at compile time and so if you put a System.get_env in your config it will run when you build, not when you start the app. Distillery solves this with config providers or this special built in syntax. If you set REPLACE_OS_VARS in the environment you run your release, any ${VAR}s in your config will be replace at run time. You can still run System.get_env in any code that is evaluated at run time, it will still work as you expect.

If you’re deploying with mix, you can get the env variables with System.get_env but if youre deploying with Distillery you have to set REPLACE_OS_VARS and then it will automatically expand any ${VAR} s you set in your config. This is a feature of Distillery. It wont go through all your code and replace any occurrence of ${VAR} though.

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement