forked from jenkinsci/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-bake.hcl
More file actions
379 lines (324 loc) · 10.3 KB
/
docker-bake.hcl
File metadata and controls
379 lines (324 loc) · 10.3 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
## Variables
variable "jdks_to_build_for_lts" {
default = [17, 21, 25]
}
variable "jdks_to_build_for_weekly" {
default = [17, 21, 25]
}
variable "default_jdk" {
default = 21
}
variable "JENKINS_VERSION" {
default = "2.534"
}
variable "WAR_SHA" {
default = "fcf13a8ebbe69d678608cc4b3885ece7d7e697d6da4c3691025a06968ddef228"
}
variable "WAR_URL" {
default = ""
}
variable "REGISTRY" {
default = "docker.io"
}
variable "JENKINS_REPO" {
default = "jenkins/jenkins"
}
variable "LATEST_WEEKLY" {
default = "false"
}
variable "LATEST_LTS" {
default = "false"
}
variable "PLUGIN_CLI_VERSION" {
default = "2.13.2"
}
variable "COMMIT_SHA" {
default = ""
}
variable "ALPINE_FULL_TAG" {
default = "3.23.2"
}
variable "ALPINE_SHORT_TAG" {
default = regex_replace(ALPINE_FULL_TAG, "\\.\\d+$", "")
}
variable "JAVA17_VERSION" {
default = "17.0.17_10"
}
variable "JAVA21_VERSION" {
default = "21.0.9_10"
}
variable "JAVA25_VERSION" {
default = "25.0.1_8"
}
variable "DEBIAN_RELEASE_LINE" {
default = "trixie"
}
variable "DEBIAN_VERSION" {
default = "20251117"
}
variable "RHEL_TAG" {
default = "9.7-1767674301"
}
variable "RHEL_RELEASE_LINE" {
default = "ubi9"
}
## Internal variables
variable "jdk_versions" {
default = {
17 = JAVA17_VERSION
21 = JAVA21_VERSION
25 = JAVA25_VERSION
}
}
variable "debian_variants" {
default = ["debian", "debian-slim"]
}
variable "current_rhel" {
default = "rhel-${RHEL_RELEASE_LINE}"
}
## Targets
target "alpine" {
matrix = {
jdk = jdks_to_build()
}
name = "alpine_jdk${jdk}"
dockerfile = "alpine/hotspot/Dockerfile"
context = "."
args = {
JENKINS_VERSION = JENKINS_VERSION
WAR_SHA = WAR_SHA
WAR_URL = war_url()
COMMIT_SHA = COMMIT_SHA
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
ALPINE_TAG = ALPINE_FULL_TAG
JAVA_VERSION = javaversion(jdk)
}
tags = linux_tags("alpine", jdk)
platforms = platforms("alpine", jdk)
}
target "debian" {
matrix = {
jdk = jdks_to_build()
variant = debian_variants
}
name = "${variant}_jdk${jdk}"
dockerfile = "debian/Dockerfile"
context = "."
args = {
JENKINS_VERSION = JENKINS_VERSION
WAR_SHA = WAR_SHA
WAR_URL = war_url()
COMMIT_SHA = COMMIT_SHA
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
DEBIAN_RELEASE_LINE = DEBIAN_RELEASE_LINE
DEBIAN_VERSION = DEBIAN_VERSION
DEBIAN_VARIANT = is_debian_slim(variant) ? "-slim" : ""
JAVA_VERSION = javaversion(jdk)
}
tags = linux_tags(variant, jdk)
platforms = platforms(variant, jdk)
}
target "rhel" {
matrix = {
jdk = jdks_to_build()
}
name = "rhel_jdk${jdk}"
dockerfile = "rhel/Dockerfile"
context = "."
args = {
JENKINS_VERSION = JENKINS_VERSION
WAR_SHA = WAR_SHA
WAR_URL = war_url()
COMMIT_SHA = COMMIT_SHA
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
RHEL_TAG = RHEL_TAG
RHEL_RELEASE_LINE = RHEL_RELEASE_LINE
JAVA_VERSION = javaversion(jdk)
}
tags = linux_tags(current_rhel, jdk)
platforms = platforms(current_rhel, jdk)
}
## Groups
group "linux" {
targets = [
"alpine",
"debian",
"rhel",
]
}
## Common functions
# return true if JENKINS_VERSION is a Weekly (one sequence of digits with a trailing literal '.')
function "is_jenkins_version_weekly" {
# If JENKINS_VERSION has more than one sequence of digits with a trailing literal '.', this is LTS
# 2.523 has only one sequence of digits with a trailing literal '.'
# 2.516.1 has two sequences of digits with a trailing literal '.'
params = []
result = length(regexall("[0-9]+[.]", JENKINS_VERSION)) < 2 ? true : false
}
# Return true if the Jenkins version corresponds to an LTS release.
function "is_jenkins_version_lts" {
# Weekly releases have a single numeric segment (e.g. 2.545),
# while LTS releases include a patch segment (e.g. 2.541.1).
params = []
result = !is_jenkins_version_weekly()
}
# Return true if the Jenkins version belongs to the 2.541.x LTS line.
# JDK 17 is kept only for this LTS for compatibility reasons.
function "is_lts_2541" {
params = []
result = is_jenkins_version_lts() && length(regexall("^2\\.541\\.", JENKINS_VERSION)) > 0
}
# Return the list of JDKs to build depending on the Jenkins release line.
# - Weekly releases must not build JDK 17 (Java 21+ required).
# - LTS 2.541.x keeps JDK 17 for backward compatibility.
# - Future LTS releases must not build JDK 17.
function "jdks_to_build" {
params = []
result = (
is_jenkins_version_weekly()
? [for jdk in jdks_to_build_for_weekly : jdk if jdk != 17]
: (
is_lts_2541()
? jdks_to_build_for_lts
: [for jdk in jdks_to_build_for_lts : jdk if jdk != 17]
)
)
}
# return a tag prefixed by the Jenkins version
function "_tag_jenkins_version" {
params = [tag]
result = notequal(tag, "") ? "${REGISTRY}/${JENKINS_REPO}:${JENKINS_VERSION}-${tag}" : "${REGISTRY}/${JENKINS_REPO}:${JENKINS_VERSION}"
}
# return a tag optionaly prefixed by the Jenkins version
function "tag" {
params = [prepend_jenkins_version, tag]
result = equal(prepend_jenkins_version, true) ? _tag_jenkins_version(tag) : "${REGISTRY}/${JENKINS_REPO}:${tag}"
}
# return a weekly optionaly prefixed by the Jenkins version
function "tag_weekly" {
params = [prepend_jenkins_version, tag]
result = equal(LATEST_WEEKLY, "true") ? tag(prepend_jenkins_version, tag) : ""
}
# return a LTS optionaly prefixed by the Jenkins version
function "tag_lts" {
params = [prepend_jenkins_version, tag]
result = equal(LATEST_LTS, "true") ? tag(prepend_jenkins_version, tag) : ""
}
# return WAR_URL if not empty, get.jenkins.io URL depending on JENKINS_VERSION release line otherwise
function "war_url" {
params = []
result = (notequal(WAR_URL, "")
? WAR_URL
: (is_jenkins_version_weekly()
? "https://get.jenkins.io/war/${JENKINS_VERSION}/jenkins.war"
: "https://get.jenkins.io/war-stable/${JENKINS_VERSION}/jenkins.war"))
}
# Return "true" if the jdk passed as parameter is the same as the default jdk, "false" otherwise
function "is_default_jdk" {
params = [jdk]
result = equal(default_jdk, jdk) ? true : false
}
# Return the complete Java version corresponding to the jdk passed as parameter
function "javaversion" {
params = [jdk]
result = lookup(jdk_versions, jdk, "Unsupported JDK version")
}
# Return an array of platforms depending on the distribution and the jdk
function "platforms" {
params = [distribution, jdk]
result = (
# Alpine
is_alpine(distribution)
? (equal(17, jdk)
? ["linux/amd64"]
: ["linux/amd64", "linux/arm64"])
# Debian slim
: is_debian_slim(distribution)
? (equal(17, jdk)
? ["linux/amd64"]
: ["linux/amd64", "linux/arm64"])
# RHEL
: is_rhel(distribution)
? ["linux/amd64", "linux/arm64", "linux/ppc64le"]
# Default (Debian)
: ["linux/amd64", "linux/arm64", "linux/s390x", "linux/ppc64le"]
)
}
# Return an array of tags for linux images depending on the distribution and the jdk
function "linux_tags" {
params = [distribution, jdk]
result = (
## Debian variants
is_debian_variant(distribution)
? debian_tags(distribution, jdk)
: [
## Always publish explicit jdk tag
tag(true, "${distribution}-jdk${jdk}"),
tag_weekly(false, "${distribution}-jdk${jdk}"),
tag_lts(false, "lts-${distribution}-jdk${jdk}"),
# Special case for Alpine
is_alpine(distribution) ? tag_weekly(false, "alpine${ALPINE_SHORT_TAG}-jdk${jdk}") : "",
# Special case for RHEL
is_rhel(distribution) ? tag_lts(true, "lts-${distribution}-jdk${jdk}") : "",
## Default JDK extra short tags (except for current rhel)
is_default_jdk(jdk) && !is_rhel(distribution) ? tag(true, distribution) : "",
is_default_jdk(jdk) && !is_rhel(distribution) ? tag_weekly(false, distribution) : "",
is_default_jdk(jdk) && !is_rhel(distribution) ? tag_lts(false, "lts-${distribution}") : "",
is_default_jdk(jdk) && !is_rhel(distribution) ? tag_lts(true, "lts-${distribution}") : "",
]
)
}
# Return if the distribution passed in parameter is Alpine
function "is_alpine" {
params = [distribution]
result = equal("alpine", distribution)
}
# Return if the distribution passed in parameter is Alpine
function "is_rhel" {
params = [distribution]
result = equal(current_rhel, distribution)
}
# Return if the distribution passed in parameter is a debian variant
function "is_debian_variant" {
params = [distribution]
result = contains(debian_variants, distribution)
}
# Return if the variant passed in parameter is the debian slim one
function "is_debian_slim" {
params = [variant]
result = equal("debian-slim", variant)
}
# Return text prefixed with "slim-" if the variant passed in parameter is the slim one
# Return only "slim" if the text passed in parameter is empty or "latest"
function "slim_prefix" {
params = [variant, text]
result = (is_debian_slim(variant)
? (equal("", text) || equal("latest", text) ? "slim" : "slim-${text}")
: text)
}
# Return text suffixed with "-slim" if the variant passed in parameter is the slim one
# Return only "slim" if the text passed in parameter is empty
function "slim_suffix" {
params = [variant, text]
result = (is_debian_slim(variant)
? (equal("", text) ? "slim" : "${text}-slim")
: text)
}
# Return an array of tags for debian images depending on the variant and the jdk passed as parameters
function "debian_tags" {
params = [variant, jdk]
result = [
## Default tags including jdk
tag(true, slim_prefix(variant, "jdk${jdk}")),
tag_weekly(false, slim_prefix(variant, "jdk${jdk}")),
tag_lts(false, "${slim_suffix(variant, "lts")}-jdk${jdk}"),
# Tags for debian only
is_debian_slim(variant) ? "" : tag_weekly(false, slim_prefix(variant, "latest-jdk${jdk}")),
is_debian_slim(variant) ? "" : tag_lts(true, "${slim_suffix(variant, "lts")}-jdk${jdk}"),
## If default jdk, short tags
is_default_jdk(jdk) ? tag(true, slim_prefix(variant, "")) : "",
is_default_jdk(jdk) ? tag_weekly(false, slim_prefix(variant, "latest")) : "",
is_default_jdk(jdk) ? tag_lts(false, slim_suffix(variant, "lts")) : "",
is_default_jdk(jdk) ? tag_lts(true, slim_suffix(variant, "lts")) : "",
]
}