Configuron is a Clojure library for managing hierarchical properties for deployment under different environments.
Sample configs.clj:
{"default" {:max-workers (+ 1 4)
:temp-dir "/tmp"
:async? true
:google-analytics? false
:aws-key "xxxxx"
:port 8090}
"dev" {:temp-dir "c:/temp"}
"devweb" {:port 5000}
"devtest" {:async? false}
"prod" {:google-analytics? true}
"prodheroku" {:aws-key "yyyyy"}}
Environment hierarchy for the above configs.clj:
default
/ \
dev prod
/ \ \
devweb devtest prodheroku
Properties are picked in this order of precedence:
- environment variables
- Leiningen project map
- concrete environment "prodheroku" (in configs.clj)
- abstract environment "prod" (in configs.clj)
- "default" (in configs.clj)
The environment name being used (e.g. "prodherouku") must be specified either as an environment variable (ENV_NAME) or in the Leiningen project map under key :env-name.
If you want to be able to draw settings from the Leiningen project map, you'll need the following plugin and hook:
:plugins [[environ/environ.lein "0.3.0"]]
:hooks [environ.leiningen.hooks]
Include the following dependency in your project.clj file:
:dependencies [[configuron "0.1.0"]]
-
create and populate resources/configs.clj
-
add resources dir in classpath in project.clj
:resource-paths ["resources"]
-
specify environment name as environment variable
export ENV_NAME="devweb"
or in the Leiningen project map in project.clj
:profiles {:devweb {:env {:env-name "devweb"}}}
-
if specifying environment name in Leiningen project map, launch with corresponding profile
lein with-profile devweb ring server
Copyright © 2013 David Lin
Distributed under the Eclipse Public License, the same as Clojure.