Skip to content

Commit

Permalink
use middleware to add to the environ config map
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell committed Sep 24, 2016
1 parent f073a54 commit decc7f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# lein-docker-compose

Small leiningen plugin that starts the services configured in your `docker-compose.yml`, discovers their port mappings, and writes that to a file for use by [environ](https://github.com/weavejester/environ).

Currently requires you to be using my fork of environ, [`[rsslldnphy/environ "1.1.1"]`](https://github.com/rsslldnphy/environ), which adds support for `.lein-docker-env` files.
Small leiningen plugin that starts the services configured in your `docker-compose.yml`, discovers their port mappings, and merges them into the map used by [environ](https://github.com/weavejester/environ).

You'll also need `docker-compose` installed and available on your path.
5 changes: 3 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(defproject lein-docker-compose "0.1.0"
(defproject lein-docker-compose "0.1.1"
:description "Leiningen plugin that provides environ with docker-compose port mappings"
:url "https://github.com/rsslldnphy/lein-docker-compose"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[circleci/clj-yaml "0.5.5"]]
:dependencies [[circleci/clj-yaml "0.5.5"]
[lein-environ "1.1.0"]]
:profiles {:dev {:resource-paths ["test/resources"]}}
:eval-in-leiningen true)
21 changes: 7 additions & 14 deletions src/lein_docker_compose/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
[clojure.java.io :as io]
[clojure.java.shell :as sh]
[clojure.string :as s]
[leiningen.core.main]))

(defn env-file
[project]
(io/file (:root project) ".lein-docker-env"))
[lein-environ.plugin]))

(defn docker-compose-file
[project]
Expand Down Expand Up @@ -49,18 +45,15 @@
(defn start-services!
[]
(let [output (sh/sh "docker-compose" "up" "-d")]
(println (:out output))
(when-not (zero? (:exit output))
(println "WARNING: Failed to bring up docker-compose services"))))

(defn write-env-to-file!
[project]
(spit (env-file project) (pr-str (discover-docker-ports project))))

(defn docker-compose-task
[func task-name project args]
(defn merge-docker-env-vars
[func project]
(start-services!)
(write-env-to-file! project)
(func task-name project args))
(merge (func project)
(discover-docker-ports project)))

(defn hooks []
(add-hook #'leiningen.core.main/apply-task #'docker-compose-task))
(add-hook #'lein-environ.plugin/read-env #'merge-docker-env-vars))

0 comments on commit decc7f1

Please sign in to comment.