fireproofsocks
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!
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
Where you get that string? There is nothing in Elixir that will “magically” replace all occurrences of
${VAR}with environment variableVAR.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 usingSystem.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 callingSystem.get_envin 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_envin 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 setREPLACE_OS_VARSin the environment you run your release, any${VAR}s in your config will be replace at run time. You can still runSystem.get_envin any code that is evaluated at run time, it will still work as you expect.If you’redeployingwithmix,youcangettheenvvariableswithSystem.get_envbutifyou’redeployingwithDistilleryyouhavetosetREPLACE_OS_VARSandthenitwillautomaticallyexpandany${VAR}syousetin yourconfig.ThisisafeatureofDistillery.Itwon’tgothroughallyourcodeandreplaceanyoccurrenceof${VAR}though.NobbZ
This is only half of the truth.
It is perfectly fine to use
System.get_envin your code, whether you use distillery or mix based deployments.You have to be careful though when you use environment variables in the
config/*.exsfiles, they will only be evaluated at “mix-time”.Similar caution has to be taken when reading environment variables in module attributes, but
REPLACE_OS_VARSwouldn’t help there either, as distillery only hooks into the application environment at the applications boot IIRC.fireproofsocks
I think I need to try the
System.get_env()calls.In my various config files, I have calls like
I think I’m doing Distillery releases. The
${DATABASE_URL}is getting set and read by my repo, and when I connect to the remote mix console, the configs all show the proper values, but it’s only when I’m actually running something using the other configs that this fails.I’m not sure what I’m missing, and I’m more confused because the behavior seems inconsistent (why does the DATABASE_URL variable seem to work by my custom IMPORTANT_URL does not? I’ve re-deployed the app several times after setting those variables, doesn’t that mean that the app re-compiled? And why does the remote iex session have access to the variables?
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}".fireproofsocks
Jola, I think you hit the nail on the head! That seems to be exactly what’s going on. Here is some more code (forgive me for not sharing more earlier):
In my config I’m really specifying an API base url and API keys which change between testing/dev/production environments:
In config:
In my module I am referencing it via a module attribute:
So can you help me understand how this is being compiled and how I should refactor it? Is that correct that module attributes get resolved at compile time and so that forces the
Application.get_env()to get evaluated? Whereas if I were to use theApplication.get_env()inside a regular function, it wouldn’t execute until run-time?jola
That’s correct. Credit to @NobbZ who pointed it out before me.
fireproofsocks
@NobbZ thank you too for your guidance! I don’t think I would have figured that out for a very long time.