weavejester/environ

How to merge multiple config files, just like config.edn , config-local.edn

mut0u opened this issue · 6 comments

mut0u commented

I am bothering abount setting up multiple config files.

I wish I can config some common settings which can be used for everyone, so I can put the common config file into git repo. And some different config for everyone, I can create a local cofig file , which will cover the settings in common setting file.

So I want the featue like django can use global config and local config.

You can create a profiles.clj file in your project directory to contain your local configuration.

A profile containing a local database URL might look like:

{:dev {:env {:database-url "..."}}}

If you keep profiles.clj out of git by adding it to .gitignore, then you can have local environment settings in profiles.clj, and global environment settings in project.clj.

mut0u commented

There is no effect when I create a profiles.clj under my project.

Call (environ/env :database-url) and return nil as a result.

I do not know how to trace this.

Are you using the lein-environ plugin? Are you using Leiningen or Boot?

mut0u commented

I use Leiningen

Does your project.clj file look like:

(defproject env-test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [environ "1.0.2"]]
  :plugins [[lein-environ "1.0.2"]])

And does your profiles.clj file look like:

{:dev {:env {:database-url "foo"}}}

And when you run lein repl:

user=> (require 'environ.core)
nil
user=> (environ.core/env :database-url)
"foo"
mut0u commented

I forget to write the plugins declaration in project.clj. Sorry. It works.
Thanks a lot.