Instantly share code, notes, and snippets.
DerTev/README.md
Last active June 15, 2023 19:31- Star 0 (0) You must be signed in to star a gist
- Fork 0 (0) You must be signed in to fork a gist
-
Select an option
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/DerTev/0c74e145e9badcebcee385638bc9fe4e.js"></script> - Save DerTev/0c74e145e9badcebcee385638bc9fe4e to your computer and use it in GitHub Desktop.
Select an option
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/DerTev/0c74e145e9badcebcee385638bc9fe4e.js"></script> Save DerTev/0c74e145e9badcebcee385638bc9fe4e to your computer and use it in GitHub Desktop. Download ZIP lein-docker Raw README.mdlein-docker
Build docker-image containing leiningen with amazon coretto.
Usage
Coming soon
Raw lein_docker.clj This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters| (require '[babashka.cli :as cli] | |
| '[babashka.fs :as fs] | |
| '[babashka.process :as shell]) | |
| (defn render-dockerfile | |
| "Returns the rendered dockerfile based on given arguments. | |
| Thanks, @amejonah1200, for the template! | |
| `java-version`: Version for the amazon-coretto-Docker-image. | |
| `lein-url`: URL to download the leiningen-script." | |
| [^String java-version ^String lein-url] | |
| (str "FROM amazoncorretto:" java-version "\n" | |
| "RUN apk -U upgrade\n" | |
| "RUN apk add --no-cache curl bash\n" | |
| "RUN curl -LO " lein-url "\n" | |
| "RUN chmod +x lein\n" | |
| "RUN mv lein /bin\n" | |
| "RUN lein self-install\n")) | |
| (defn parse-args | |
| "Parse args from map containing the command line arguments, possible to get from [[*command-line-args*]]." | |
| [args] | |
| (cli/parse-opts args {:alias {:jv :java-version | |
| :lu :lein-url | |
| :t :docker-tag | |
| :d :temp-dir} | |
| :coerce {:java-version :string | |
| :lein-url :string | |
| :docker-tag :string | |
| :temp-dir :string} | |
| :exec-args {:java-version "17-alpine" | |
| :lein-url "https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein" | |
| :docker-tag "leiningen-coretto" | |
| :temp-dir "/tmp/lein-docker/"}})) | |
| (defn write-dockerfile! | |
| "Writes dockerfile from [[render-dockerfile]]. | |
| `parsed-args`: Map with the return value of [[parse-args]]." | |
| [parsed-args] | |
| (fs/create-dirs (:temp-dir parsed-args)) | |
| (->> (render-dockerfile (:java-version parsed-args) | |
| (:lein-url parsed-args)) | |
| (spit (str (:temp-dir parsed-args) | |
| "Dockerfile")))) | |
| (let [start-time (.currentTimeMillis System) | |
| parsed-args (-> *command-line-args* | |
| parse-args)] | |
| (println "Write Dockerfile...") | |
| (write-dockerfile! parsed-args) | |
| (println "Build Docker-Image...") | |
| (shell/shell {:dir (:temp-dir parsed-args)} | |
| "docker" "build" (str "-t" (:docker-tag parsed-args)) ".") | |
| (println (str "Finished in " (- (.currentTimeMillis System) start-time) "ms!"))) |