Comments (5)
It would all depend on how you choose to work with env overrides, but there are options. The simplest way: you can have you config.edn
living in the classpath / file system. You would start your application with something like -Dconf=...
and export ENV
variables to override env specific properties.
Besides exporting ENV
variables manually / with a script, you can use something like Consul or etcd or Zookeeper to read those values.
Both solutions above would resolve in just:
(load-config)
since cprop merges ENV variables by default.
Using a specific conf.env
file for a specific environment is also of course an option. It can live in classpath / file system or could also live in consul/etc/zookeeper where, depending on env would be pushed to the app (or its docker image). In which case the you would just do:
(load-config :merge [(from-file "conf.env")])
or from-resource
, depending where this file is being placed.
from cprop.
from the docs:
By default cprop
would look in two places for configuration files:
- classpath: for the
config.edn
resource - file system: for a path identified by the
conf
system property
If both are there, they will be merged. A file system
source would override matching properties from a classpath
source,
and the result will be merged with System properties
and then merged with ENV variables
for all the matching properties.
check out cprop test to see (load-config)
in action.
so the idea is that if relies on the configuration file (i.e. config.edn
, or another, non default name) to be "there". All the merges happen to this file.
For example this would work:
$ lein try cprop
user=> (use 'cprop.core)
user=> (spit "i-need-to-exist.edn" "{:a 42}")
user=> (load-config :file "i-need-to-exist.edn")
{:a 42}
Are you looking for a different behavior?
from cprop.
Ok I see, when I read it the first time I didn't think that at least one of :file
or config.edn
on classpath was mandatory.
I think that as a default behavior explicit (empty map) is better than implicit (expecting a file called config.edn
somewhere on the classpath).
But it is a matter of taste that is up to you desinging the lib, so don't hesitate to close the issue, thanks.
from cprop.
Currently, in case it does not find a resource
or a file
cprop would complain. This complaint is quite welcome beyond development, since it communicates the fact that the file that was given via ENV
or -D
or a classpath was not found: i.e. it is clear, and does not start an application without its configuration.
But you could be right.. to allow load-config
to just take a map and then run all the merges on that map might be useful in development / testing. When would you use it and how?
from cprop.
I am using cprop
for configuring a system
(from component library).
All the config files are under a config
directory and I intended to load them as follows:
(defn merge-configs [conf-from-app]
(let [conf-from-sys (from-system-props)
conf-from-env (from-env)
env (name (or (:env conf-from-app)
(:env conf-from-sys)
(:env conf-from-env)
(throw (IllegalArgumentException. ":env is missing"))))]
(load-config :merge [(from-file "config/defaults.edn")
conf-from-app
(from-file (str "config/" env ".edn"))
conf-from-sys
conf-from-env])))
That's how I got an error.
Now I moved out "config/defaults.edn"
into a :file
parameter.
from cprop.
Related Issues (20)
- How to update the java env settings? HOT 2
- Add CLI as a source of configuration data HOT 4
- Feature Request: EDN to Properties class HOT 10
- Converting to properties (t/map->properties) fails with Mac environmental variables
- Support for ~ shorthand in load-config :file HOT 2
- :env key? HOT 8
- CLJC files are incompatible with ClojureScript HOT 4
- Non-numeric values are parsed as numbers HOT 8
- why env has a higher priority than command line arguments? HOT 6
- Merging a nil value nils the entire config HOT 3
- Question marks in config values - from ENV -> cprop ? HOT 2
- better match the behavior of `assoc-in` HOT 2
- cprop cannot handle setting nils HOT 2
- `cprop.tools/contains-in?` doesn't work with vectors HOT 1
- `load-config :merge` option not merging in specified order HOT 2
- enhancement to `:as-is?` for specific value conversions HOT 2
- Empty files cause issues while loading HOT 8
- Low priority bug : `cprop.tool/map->env-file` doesn't support dotted namespaced keys
- Confusing readme. HOT 1
- parse-runtime-args doesn't exist in the codebase HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cprop.