Skip to content

Commit

Permalink
Merge pull request #7 from mccraigmccraig/feature/config-cmd-files
Browse files Browse the repository at this point in the history
Specify command and extra files in project.clj
  • Loading branch information
hugoduncan committed Aug 22, 2014
2 parents bb8c653 + b6258ee commit 16190e2
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/leiningen/uberimage.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,32 @@

(defn dockerfile
"Return a dockerfile string"
[{:keys [base-image]}]
(format "FROM %s
ADD uberjar.jar uberjar.jar
CMD [\"/usr/bin/java\", \"-jar\", \"/uberjar.jar\"]"
base-image))
[{:keys [cmd files base-image]}]
(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"
(str "CMD [" cmd-str "]")]
(for [[tar-path local-path] files]
(str "ADD " tar-path " " tar-path)))
(string/join "\n"))))

(defn buildtar
"Return an InputStream that will deliver a tar archive with a Dockerfile
and the uberjar."
[tar-output-stream piped-output-stream standalone-filename options]
[tar-output-stream piped-output-stream standalone-filename
{:keys [files] :as options}]
(with-open [piped-output-stream piped-output-stream
tar-output-stream tar-output-stream]
(tar-entry-from-string
tar-output-stream "Dockerfile" (dockerfile options))
(tar-entry-from-file
tar-output-stream "uberjar.jar" (file standalone-filename))))
tar-output-stream "uberjar.jar" (file standalone-filename))
(doseq [[tar-path local-path] files]
(tar-entry-from-file
tar-output-stream tar-path (file local-path)))))

(def info-timbre-config
"A basic timbre configuration for use with info level logging."
Expand Down Expand Up @@ -69,7 +79,8 @@ CMD [\"/usr/bin/java\", \"-jar\", \"/uberjar.jar\"]"
(defn ^{:doc (help)} uberimage
[project & args]
(let [{:keys [options arguments summary errors]} (parse-opts args cli-options)
{:keys [base-image endpoint]} options]
{:keys [base-image endpoint]} options
options (merge (:uberimage project) options)]
(when errors
(throw (ex-info
(str "Invalid arguments: " (string/join " " errors))
Expand Down

0 comments on commit 16190e2

Please sign in to comment.