|
1 | 1 | (ns build
|
2 | 2 | (:require [clojure.tools.build.api :as b]
|
3 | 3 | [org.corfield.build :as bb]
|
4 |
| - [clojure.string :as str]) |
| 4 | + [clojure.string :as str] |
| 5 | + [juxt.pack.api :as pack]) |
| 6 | + (:import [com.google.cloud.tools.jib.api JibContainer]) |
5 | 7 | (:refer-clojure :exclude [test]))
|
6 | 8 |
|
7 | 9 | (def lib 'swirrl/csv2rdf)
|
|
63 | 65 | :class-dir class-dir
|
64 | 66 | :uber-file "target/csv2rdf-app.jar"
|
65 | 67 | })))
|
| 68 | + |
| 69 | +;; A tag name must be valid ASCII and may contain lowercase and uppercase |
| 70 | +;; letters, digits, underscores, periods and dashes |
| 71 | +;; https://docs.docker.com/engine/reference/commandline/tag/#extended-description |
| 72 | +(defn tag [s] |
| 73 | + (when s (str/replace s #"[^a-zA-Z0-9_.-]" "_"))) |
| 74 | + |
| 75 | +(def repo "europe-west2-docker.pkg.dev/swirrl-devops-infrastructure-1/public") |
| 76 | + |
| 77 | +(defn docker [opts] |
| 78 | + (let [tags (->> ["rev-parse HEAD" |
| 79 | + "describe --tags --always" |
| 80 | + "branch --show-current"] |
| 81 | + (map #(tag (b/git-process {:git-args %}))) |
| 82 | + (remove nil?)) |
| 83 | + image-type (get opts :image-type :docker) |
| 84 | + build-args {:basis (b/create-basis {:project "deps.edn" :aliases [:docker]}) |
| 85 | + ;; If we don't include a tag in the :image-name, then pack implicitly |
| 86 | + ;; tags the image with latest, even when we specify additional tags. So |
| 87 | + ;; choose a tag arbitrarily to be part of the :image-name, and then |
| 88 | + ;; provide the rest in :tags. |
| 89 | + :image-name (str repo "/csv2rdf:" (first tags)) |
| 90 | + :tags (set (rest tags)) |
| 91 | + :image-type image-type |
| 92 | + :base-image "eclipse-temurin:17" ;; An openJDK 17 base docker provided by https://github.com/adoptium/containers#containers |
| 93 | + } |
| 94 | + publish-args {:platforms #{:linux/amd64 :linux/arm64} |
| 95 | + |
| 96 | + ;; NOTE Not as documented! |
| 97 | + ;; The docstring states that these should be |
| 98 | + ;; :to-registry {:username ... :password ...} |
| 99 | + ;; but alas, that is a lie. |
| 100 | + ;; https://github.com/juxt/pack.alpha/issues/101 |
| 101 | + :to-registry-username "_json_key" |
| 102 | + :to-registry-password (System/getenv "GCLOUD_SERVICE_KEY")} |
| 103 | + args (if (= :remote (:to opts)) |
| 104 | + (merge build-args publish-args) |
| 105 | + build-args) |
| 106 | + ^JibContainer container (pack/docker args)] |
| 107 | + (println (.. container (getDigest) (getHash))))) |
0 commit comments