Skip to content

Commit

Permalink
Include additional instructions in Dockerfiles
Browse files Browse the repository at this point in the history
Allows the insertion of additional Dockerfile instructions

The :instructions value is taken from the :uberimage options map
in project.clj and specifies a list of Dockerfile instructions to
be inserted immediately after the FROM instruction at the start
of the Dockerfile.
  • Loading branch information
mccraigmccraig authored and hugoduncan committed Sep 26, 2014
1 parent e4ae1a4 commit 23a196a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ image's `CMD` and to place extra files into the image.

```clj
:uberimage {:cmd ["/bin/dash" "/myrunscript" "param1" "param2"]
:instructions ["RUN apt-get update && apt-get -y dist-upgrade"]
:files {"myrunscript" "docker/myrunscript"}
:tag "user/repo:tag"}
```

The `:cmd` value maps directly to a Dockerfile CMD statement

The `:instructions` value specifies a list of Dockerfile instructions
to be inserted into the generated Dockerfile immediately after
the `FROM` instruction at the start of the Dockerfile

The `:files` value is a map of additional files to be copied into the
docker image. Keys are docker image target paths and values are lein
project source paths.
Expand Down
8 changes: 5 additions & 3 deletions src/leiningen/uberimage.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@

(defn dockerfile
"Return a dockerfile string"
[{:keys [cmd files base-image]}]
[{:keys [cmd files base-image instructions]}]
(let [cmd (or cmd ["/usr/bin/java" "-jar" "/uberjar.jar"])
cmd (if (sequential? cmd) cmd [cmd])
cmd-str (->> (for [s cmd] (str "\"" s "\""))
(string/join ","))]
(->> (concat [(str "FROM " base-image)
"ADD uberjar.jar uberjar.jar"
(->> (concat [(str "FROM " base-image)]
instructions
["ADD uberjar.jar uberjar.jar"
(str "CMD [" cmd-str "]")]
(for [[tar-path local-path] files]
(str "ADD " tar-path " " tar-path)))
(filter identity)
(string/join "\n"))))

(defn buildtar
Expand Down

0 comments on commit 23a196a

Please sign in to comment.