4

The https://github.com/yogthos/config approach let's you lay out per-profile env variables in separate files, like the below , in a project.clj .

Per the below, one can use lein with-profile prod uberjar or lein with-profile dev repl and the like.

But my issue is I have been unable to figure out how to place some common values into a shared area, accessible by dev, stage, prod profiles.

Basic example

(defproject edn-config-test "0.1.0-SNAPSHOT" ... :profiles {:shared {:resource-paths ["config/shared"]} :dev {:resource-paths ["config/dev"]} :stage {:resource-paths ["config/stage"]} :prod {:resource-paths ["config/prod"]}} ... 

(with files)

config/shared/config.edn config/dev/config.edn config/stage/config.edn config/prod/config.edn 

I tried this without luck

lein with-profile shared,prod lein , borrowing from the composite approach in https://github.com/technomancy/leiningen/blob/stable/doc/PROFILES.md#composite-profiles

When I do that, I only get variables in prod profile, for example.

1 Answer 1

1

I think it is a limitation of config. I tried this (more explicit):

:profiles {:dev {:resource-paths ["config/shared" "config/dev"]} :prod {:resource-paths [ "config/prod" "config/shared"]}} 

However, the last file wins and the first is ignored. So for :dev the shared stuff is ignored, and for :prod the prod stuff is ignored (like it doesn't exist):

config/dev/config.edn => {:special-val :dev-val} config/prod/config.edn => {:special-val :prod-val} cat config/shared/config.edn => {:shared-val 42} 

and results:

> lein with-profile prod run (:shared-val env) => 42 (:special-val env) => nil > lein with-profile dev run (:shared-val env) => nil (:special-val env) => :dev-val 

Perhaps you'd like to submit an enhancement PR to the project?


Here is the problem. It uses io/resource to read config.edn, which implicitly expects there to be only one file config.edn anywhere on the classpath:

(defn- read-config-file [f] (try (when-let [url (io/resource f)] (with-open [r (-> url io/reader PushbackReader.)] (edn/read r))) ... (read-config-file "config.edn") 

So you'd have to get away from the hard-coded filename config.edn, and make something like config-dev.edn, config-prod.edn, and config-shared.edn. At least then they could all live in a single ./resources dir.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.