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

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement