|
4 | 4 | [clojure.string :as str] |
5 | 5 | [docker-clojure.dockerfile.lein :as lein] |
6 | 6 | [docker-clojure.dockerfile.tools-deps :as tools-deps] |
7 | | - [docker-clojure.dockerfile.shared :refer [copy-resource-file! entrypoint]] |
| 7 | + [docker-clojure.dockerfile.shared :refer [copy-resource-file! render-template]] |
8 | 8 | [docker-clojure.log :refer [log]])) |
9 | 9 |
|
10 | 10 | (defn build-dir [{:keys [base-image-tag jdk-version build-tool]}] |
|
19 | 19 | (defn all-prereqs [dir variant] |
20 | 20 | (tools-deps/prereqs dir variant)) |
21 | 21 |
|
22 | | -(defn all-contents [installer-hashes variant] |
23 | | - (concat |
24 | | - ["" "### INSTALL LEIN ###"] |
25 | | - (lein/install |
26 | | - installer-hashes |
27 | | - (assoc variant :build-tool-version |
28 | | - (get-in variant [:build-tool-versions "lein"]))) |
29 | | - ["" "### INSTALL TOOLS-DEPS ###"] |
30 | | - (tools-deps/install |
31 | | - installer-hashes |
32 | | - (assoc variant :build-tool-version |
33 | | - (get-in variant [:build-tool-versions "tools-deps"]))) |
34 | | - [""] |
35 | | - (entrypoint variant) |
36 | | - ["" "CMD [\"-M\", \"--repl\"]"])) |
| 22 | +(defn copy-java? |
| 23 | + "Debian variants copy the JDK in from an eclipse-temurin image; the temurin |
| 24 | + base images already have it." |
| 25 | + [{:keys [distro]}] |
| 26 | + (contains? #{:debian :debian-slim} (-> distro namespace keyword))) |
37 | 27 |
|
38 | | -(defn copy-java-from-temurin-contents |
39 | | - [{:keys [jdk-version] :as _variant}] |
40 | | - ["ENV JAVA_HOME=/opt/java/openjdk" |
41 | | - (str "COPY --from=eclipse-temurin:" jdk-version " $JAVA_HOME $JAVA_HOME") |
42 | | - "ENV PATH=\"${JAVA_HOME}/bin:${PATH}\"" |
43 | | - ""]) |
| 28 | +(defn entrypoint? |
| 29 | + "JDK 16+ ships a `repl` so we install our wrapper entrypoint for it." |
| 30 | + [{:keys [jdk-version]}] |
| 31 | + (>= jdk-version 16)) |
44 | 32 |
|
45 | | -(defn contents [installer-hashes {:keys [build-tool distro] :as variant}] |
46 | | - (str/join "\n" |
47 | | - (concat [(format "FROM %s" (:base-image-tag variant)) |
48 | | - ""] |
49 | | - (case (-> distro namespace keyword) |
50 | | - (:debian :debian-slim) (copy-java-from-temurin-contents variant) |
51 | | - []) |
52 | | - (case build-tool |
53 | | - :docker-clojure.core/all (all-contents installer-hashes variant) |
54 | | - "lein" (lein/contents installer-hashes variant) |
55 | | - "tools-deps" (tools-deps/contents installer-hashes variant))))) |
| 33 | +(defn for-build-tool |
| 34 | + "Return `variant` with `:build-tool-version` set to the given tool's version. |
| 35 | + Single-build-tool variants already carry it; the combined `latest` image |
| 36 | + pulls each tool's version from `:build-tool-versions`." |
| 37 | + [variant build-tool] |
| 38 | + (cond-> variant |
| 39 | + (nil? (:build-tool-version variant)) |
| 40 | + (assoc :build-tool-version (get-in variant [:build-tool-versions build-tool])))) |
| 41 | + |
| 42 | +(defn body |
| 43 | + "The build-tool install section(s) that go between the base image setup and |
| 44 | + the entrypoint. The combined `latest` image stacks both behind headers." |
| 45 | + [installer-hashes {:keys [build-tool] :as variant}] |
| 46 | + (case build-tool |
| 47 | + "lein" (lein/install installer-hashes variant) |
| 48 | + "tools-deps" (tools-deps/install installer-hashes variant) |
| 49 | + :docker-clojure.core/all |
| 50 | + (str "\n### INSTALL LEIN ###\n" |
| 51 | + (lein/install installer-hashes (for-build-tool variant "lein")) |
| 52 | + "\n\n### INSTALL TOOLS-DEPS ###\n" |
| 53 | + (tools-deps/install installer-hashes (for-build-tool variant "tools-deps"))))) |
| 54 | + |
| 55 | +(defn command |
| 56 | + [{:keys [build-tool] :as variant}] |
| 57 | + (case build-tool |
| 58 | + "lein" (lein/command variant) |
| 59 | + "tools-deps" (tools-deps/command variant) |
| 60 | + :docker-clojure.core/all "CMD [\"-M\", \"--repl\"]")) |
| 61 | + |
| 62 | +(defn contents [installer-hashes variant] |
| 63 | + (render-template |
| 64 | + "templates/Dockerfile.tmpl" |
| 65 | + {:from (:base-image-tag variant) |
| 66 | + :copy-java (copy-java? variant) |
| 67 | + :jdk-version (:jdk-version variant) |
| 68 | + :body (body installer-hashes variant) |
| 69 | + :entrypoint (entrypoint? variant) |
| 70 | + :cmd (command variant)})) |
56 | 71 |
|
57 | 72 | (defn shared-prereqs [dir {:keys [build-tool]}] |
58 | 73 | (let [entrypoint (case build-tool |
|
0 commit comments