-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.clj
107 lines (93 loc) · 3.81 KB
/
build.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(ns build
(:require [clojure.tools.build.api :as b]
[org.corfield.build :as bb]
[clojure.string :as str]
[juxt.pack.api :as pack])
(:import [com.google.cloud.tools.jib.api JibContainer])
(:refer-clojure :exclude [test]))
(def lib 'swirrl/csv2rdf)
(def version (str/replace (or (System/getenv "CIRCLE_TAG")
"v0.5.999-SNAPSHOT")
#"^v" ""))
(def class-dir "target/classes")
(def jar-file (format "target/%s-%s.jar" (name lib) version))
(defn test
"Run the tests"
[opts]
(bb/run-tests (assoc opts :aliases [:with-logging :dev])))
(defn build-lib
"Run the CI pipeline of tests (and build the JAR)."
[opts]
(-> opts
(assoc :lib lib
:version version
:src-pom "template/pom.xml")
(bb/clean)
(bb/jar)))
(defn install
"Install the JAR locally."
[opts]
(-> opts
(assoc :lib lib :version version)
(bb/install)))
(defn deploy
"Deploy the JAR to Clojars.
NOTE: this expects a tag to be set; typically done via the github release UI."
[opts]
(-> opts
(assoc :lib lib :version version)
(bb/deploy)))
(defn clean [_]
(b/delete {:path "target"}))
;; NOTE this is not yet built by CI
(defn build-app
"Build an uberjar for the command line app"
[_]
(clean nil)
(b/copy-dir {:src-dirs ["resources" "profiles/with-logging/resources"]
:target-dir class-dir})
(let [basis (b/create-basis {:aliases [:cli :with-logging]})]
(b/compile-clj {:basis basis
:class-dir class-dir
:src-dirs ["src"]})
(bb/uber {:main 'csv2rdf.main
:basis basis
:class-dir class-dir
:uber-file "target/csv2rdf-app.jar"
})))
;; A tag name must be valid ASCII and may contain lowercase and uppercase
;; letters, digits, underscores, periods and dashes
;; https://docs.docker.com/engine/reference/commandline/tag/#extended-description
(defn tag [s]
(when s (str/replace s #"[^a-zA-Z0-9_.-]" "_")))
(def repo "europe-west2-docker.pkg.dev/swirrl-devops-infrastructure-1/public")
(defn docker [opts]
(let [tags (->> ["rev-parse HEAD"
"describe --tags --always"
"branch --show-current"]
(map #(tag (b/git-process {:git-args %})))
(remove nil?))
image-type (get opts :image-type :docker)
build-args {:basis (b/create-basis {:project "deps.edn" :aliases [:docker]})
;; If we don't include a tag in the :image-name, then pack implicitly
;; tags the image with latest, even when we specify additional tags. So
;; choose a tag arbitrarily to be part of the :image-name, and then
;; provide the rest in :tags.
:image-name (str repo "/csv2rdf:" (first tags))
:tags (set (rest tags))
:image-type image-type
:base-image "eclipse-temurin:17" ;; An openJDK 17 base docker provided by https://github.com/adoptium/containers#containers
}
publish-args {:platforms #{:linux/amd64 :linux/arm64}
;; NOTE Not as documented!
;; The docstring states that these should be
;; :to-registry {:username ... :password ...}
;; but alas, that is a lie.
;; https://github.com/juxt/pack.alpha/issues/101
:to-registry-username "_json_key"
:to-registry-password (System/getenv "GCLOUD_SERVICE_KEY")}
args (if (= :remote (:to opts))
(merge build-args publish-args)
build-args)
^JibContainer container (pack/docker args)]
(println (.. container (getDigest) (getHash)))))