Configuration Sharing in Leiningen project.clj

I have a Clojure project that uses the Leiningen lein-beanstalk plugin to deploy my application to Amazon Stretch Bean Machine .

My Elastic Beanstalk has several environments (for example, development, production, production, etc.), each of which has a different configuration. Configuration is controlled by Elastic Beanstalk environment properties, which are set as system properties in the JVM. lein-beanstalk manages these properties with the following entry in project.clj:

(defproject eb-app "1.0-SNAPSHOT"
  :aws {:beanstalk {:environments [{:name "staging"
                                    :env {"com.example.fooLimit" "3"
                                          "com.example.barName" "BAR"}}
                                   {:name "production"
                                    :env {"com.example.fooLimit" "27"
                                          "com.example.barName" "BAR"}}]}})

In this example, only the variable com.example.fooLimitchanges between my environments, so I would like to use var to store shared conf. Since defprojectthis is a macro that quotes everything, I can accomplish what I want with the unquote syntax:

(def cfg {"com.example.barName" "BAR"})

(defproject eb-app "1.0-SNAPSHOT"
  :aws {:environments [{:name "staging"
                        :env ~(merge cfg {"com.example.fooLimit" "3"}})
                       {:name "production"
                        :env ~(merge cfg {"com.example.fooLimit" "27"}})}]}})

My question is, is this common in Clojure projects, or if there is a more idiomatic or standard way (among Clojure programmers) for DRY up project.clj?

+4
source share

Source: https://habr.com/ru/post/1543040/


All Articles