-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb.edn
165 lines (139 loc) · 6.38 KB
/
bb.edn
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{:deps {local/deps {:local/root "."}}
:min-bb-version "1.3.189"
:paths ["bb" "src" "resources"]
:pods {com.github.jackdbd/jsoup {:version "0.4.0"}}
:tasks
{:requires ([babashka.process :refer [process check]]
[clojure.edn :as edn]
[clojure.java.shell :refer [sh]]
[clojure.string :as str]
[fosdem-dl.talks-cli :refer [talks-cli]]
[fosdem-dl.tracks-cli :refer [tracks-cli]]
[tasks])
:init (do
(def project (-> (edn/read-string (slurp "deps.edn")) :aliases :neil :project))
(def group-id (first (str/split (str (:name project)) (re-pattern "/"))))
(def app-name (last (str/split (str (:name project)) (re-pattern "/"))))
(def app-version (:version project))
(def jar (format "target/%s-%s.jar" app-name (:version project)))
(def registry-namespace "jackdbd")
(def image-tag (format "ghcr.io/%s/%s:%s" registry-namespace app-name app-version))
(def remote-image-version "latest")
(def remote-image-tag (format "ghcr.io/%s/%s:%s" registry-namespace app-name remote-image-version)))
build:bb-uber
{:doc "Build Babashka uberjar (see: https://book.babashka.org/#_uberjar)"
:depends [clean:artifacts]
:task (let [debug? false
cmd (if (= "true" (System/getenv "DEBUG_BB_UBERJAR"))
(format "bb --debug uberjar %s --main fosdem-dl.cli " jar)
(format "bb uberjar %s --main fosdem-dl.cli " jar))]
(println cmd)
(println (format "Tip: it must be called with bb %s, not java -jar %s" jar jar))
(shell cmd))}
build:uber
{:doc "Build uberjar"
:depends [clean:artifacts]
:task (clojure "-T:build uber")}
build:binary
{:doc "Compile statically-linked binary with GraalVM native-image (Linux only)"
:depends [build:uber]
:task (shell "script/compile.sh")}
cp
{:doc "Print classpath"
:task (tasks/print-classpath)}
clean
{:doc "Remove compilation artifacts and pods (in parallel)"
:task (run '-clean {:parallel true})}
-clean
{:depends [clean:artifacts clean:pods]}
clean:artifacts
{:doc "Remove compilation artifacts (uberjars, binaries)"
:task (clojure "-T:build clean")}
clean:downloads
{:doc "Remove downloads"
:task (let [cmd "rm -rf ./downloads"]
(println cmd)
(shell cmd))}
clean:pods
{:doc "Remove compilation artifacts"
:task (let [cmd "rm -rf ./resources/pod"]
(println cmd)
(shell cmd))}
cli
{:doc "Run CLI as Babashka script (e.g. 'bb cli talks -y 2019 -t llvm', 'bb cli tracks -y 2020')"
:task (let [list *command-line-args*
cmd (conj list "./src/fosdem_dl/cli.clj")]
(shell cmd))}
cli:debug
{:doc "Run CLI with bb --debug -x fosdem-dl.cli/-main"
;; The usage of clojure.java.io/resource assumes a classpath, so
;; when this is used in your uberscript, you still have to set a
;; classpath and bring the resources along.
;; https://book.babashka.org/#_classpath
;; cmd (format "bb --debug --classpath src:resources -x fosdem-dl.fosdem-dl/-main")
;; cmd (format "bb --debug --classpath src:resources -x fosdem-dl.fosdem-dl/-main --help")
:task (let [cmd (into ["bb" "--debug" "-x" "fosdem-dl.cli/-main"] *command-line-args*)]
(println cmd)
(shell cmd))}
dep:upgrade
{:doc "Upgrade all dependencies declared in deps.edn"
:task (shell "neil dep upgrade")}
container:build
{:doc "Build container image"
:task (let [created-date (str (java.time.ZonedDateTime/now))
;; On NixOS, the SOURCE_DATE_EPOCH environment variable is often
;; set to UTC 1980-01-01 00:00:00 as part of the system’s
;; commitment to reproducible builds. But if we want tools like
;; `docker image ls` to display the correct created date, we need
;; to set SOURCE_DATE_EPOCH when building the container image.
epoch (str/trim (:out (sh "date" "+%s")))
options ["--file" "Dockerfile"
"--build-arg" (str "APP_NAME=" app-name)
"--build-arg" (str "APP_VERSION=" app-version)
"--build-arg" (str "CREATED_DATE=" created-date)
"--build-arg" (str "JSOUP_POD_VERSION=" "0.4.0")
#_"--no-cache"
"--tag" image-tag]
cmd (format "docker build ./ %s" (str/join " " options))]
(println (format "SOURCE_DATE_EPOCH=%s %s" epoch cmd))
(shell {:extra-env {"SOURCE_DATE_EPOCH" epoch}} cmd))}
container:cli
{:doc "Run CLI in a container"
;; :depends [container:build]
:task (let [cmd (str/join " " (concat [(format "docker run --rm %s" image-tag)] *command-line-args*))]
(println cmd)
(shell cmd))}
container:dive
{:doc "Inspect layers of a local container image (with dive)"
;; :depends [container:build]
:task (shell (format "dive %s" image-tag))}
container:inspect
{:doc "Inspect a container image hosted on Container Registry (with skopeo)"
:task (shell (format "skopeo inspect docker://%s" remote-image-tag))}
container:push
{:doc "Push container image to GitHub Container Registry"
;; :depends [container:build container:scan]
:task (let [cmd (format "docker push %s" image-tag)]
(println cmd)
(shell cmd))}
container:scan
{:doc "Scan container image with Trivy"
;; :depends [container:build]
:task (shell (format "trivy image --severity MEDIUM,HIGH,CRITICAL -f table %s" image-tag))}
container:tags
{:doc "List all available tags for a container image hosted on Container Registry (with skopeo)"
:task (shell (format "skopeo list-tags docker://ghcr.io/%s/%s" registry-namespace app-name))}
-graph:gen
{:task (clojure "-X:hiera" :layout :vertical)}
-graph:copy
{:task (shell "cp target/hiera/namespaces.png resources/img")}
graph
{:depends [-graph:gen -graph:copy]
:doc "Generate a graph of dependencies between namespaces and copy the image to resources/img"
:task (shell "feh resources/img/namespaces.png")}
pod:download
{:doc "Download a version of pod-jackdbd-jsoup hosted on GitHub Releases (see POD_JACKDBD_JSOUP_VERSION environment variable)"
:task (shell "./download_pod_jackdbd_jsoup.sh")}
test
{:doc "Run all tests"
:task (shell "bb test_runner.clj")}}}