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.

jola

jola

That’s correct. Credit to @NobbZ who pointed it out before me.

fireproofsocks

fireproofsocks

@NobbZ thank you too for your guidance! I don’t think I would have figured that out for a very long time.

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

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
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
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

We're in Beta

About us Mission Statement