Anyone know the best way to set environment variables when testing when you use aero
? Usually weโve used environ
and set environment variables in .profiles.clj
when testing. Is it best to just also include environ
?
@shan You can use #env
tag
If you need fallbacks, you can do this:
#or [#env FOOBAR :fallback]
Thanks @dominicm. Thatโs fine for loading the env vars but we want to be able to set some env vars for local development. Usually weโd do this with .profiles.clj
and use environ
.
Our main problem is that we want to load different configs depending on what an environment is set as (say we have region
ENV VAR). This env var can be set up using consul in our prod and pre-prod environments but I was wondering how weโd set this in our local dev environments. We also want to throw an exception if that env var is not set.
Could possibly be going about solving this problem in the wrong way tho
@shan: I'd recommend the #profile
tag in that case ๐.
When you call into aero, you can provide the profile as a value. Your get-profile would perhaps look like this:
(defn get-profile []
(doto (keyword (System/getenv "region")) assert))
(aero/read-config (io/resource "config.edn") {:profile (get-profile)})
Then in config.edn:
{:db-url #profile {:prod "<ddb://prod/foobar>"
:dev "ddb:<mem://myapp>"}
@shan ^^
๐ how would you go about setting the region
env var locally?
@shan Generally, I don't. In the dev/dev.clj file, we call (new-system :dev)
.
ah ok
https://github.com/juxt/edge/blob/master/dev/user.clj#L18-L28 โ example of this
although I might be inclined to update the example to have better boundaries. But that's another matter ๐
cheers, might have to rethink our workflow
:thinking_face: As long as you have a function which produces a system & takes a profile, you're golden. In your -main
function, you use the (get-profile)
function, this is what will be called in the uberjar.
In dev, you have the dev/
directory on the classpath. And when you have your start
stop
reset
going on in there, that takes care of enforcing the :dev
profile.
Let me know if you need any help ๐
actually making changes to an existing app atm but will ask if I have any relevant questions
okay