Fork me on GitHub
#juxt
<
2017-06-05
>
shan13:06:04

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?

dominicm14:06:27

@shan You can use #env tag

dominicm14:06:55

If you need fallbacks, you can do this: #or [#env FOOBAR :fallback]

shan14:06:32

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.

shan14:06:57

Could possibly be going about solving this problem in the wrong way tho

dominicm14:06:12

@shan: I'd recommend the #profile tag in that case 🙂.

dominicm14:06:09

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 ""
                   :dev "ddb:"}

shan14:06:05

👍 how would you go about setting the region env var locally?

dominicm14:06:56

@shan Generally, I don't. In the dev/dev.clj file, we call (new-system :dev).

dominicm15:06:58

although I might be inclined to update the example to have better boundaries. But that's another matter 🙂

shan15:06:01

cheers, might have to rethink our workflow

dominicm15:06:30

: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 🙂

shan15:06:04

actually making changes to an existing app atm but will ask if I have any relevant questions