Skip to content

Commit 8e63786

Browse files
committed
chore(windows): use docker bake to generate the docker compose file
1 parent a2a685b commit 8e63786

15 files changed

+300
-162
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ work-pester-jenkins-windows/
1616
/**/windows/**/jenkins-plugin-cli.ps1
1717
/**/windows/**/jenkins-support.psm1
1818

19+
build-windows_*.yaml
20+
1921
tests/**/Dockerfile\.*

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ stage('Build') {
6464
stage("Build ${imageType}") {
6565
infra.withDockerCredentials {
6666
powershell './make.ps1 build'
67+
archiveArtifacts artifacts: 'build-windows_*.yaml', allowEmptyArchive: true
6768
}
6869
}
6970

@@ -117,7 +118,7 @@ stage('Build') {
117118

118119
if (!infra.isTrusted()) {
119120
// This list can be updated with the following command:
120-
// make show | jq -r '.target | keys[]' | sort
121+
// make show-linux | jq -r '.target | keys[]' | sort
121122
def images = [
122123
'alpine_jdk21',
123124
'alpine_jdk25',

Makefile

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ export BUILDKIT_PROGRESS=plain
99
## Required to have the commit SHA added as a Docker image label
1010
export COMMIT_SHA=$(shell git rev-parse HEAD)
1111

12+
current_os := $(shell uname -s)
1213
current_arch := $(shell uname -m)
14+
15+
export OS := $(shell \
16+
case "$(current_os)" in \
17+
(Linux) echo linux ;; \
18+
(Darwin) echo linux ;; \
19+
(MINGW*|MSYS*|CYGWIN*) echo windows ;; \
20+
(*) echo unknown ;; \
21+
esac)
22+
1323
export ARCH ?= $(shell \
1424
case $(current_arch) in \
1525
(x86_64) echo "amd64" ;; \
@@ -31,7 +41,7 @@ TEST_SUITES ?= $(CURDIR)/tests
3141
## Check the presence of a CLI in the current PATH
3242
check_cli = type "$(1)" >/dev/null 2>&1 || { echo "Error: command '$(1)' required but not found. Exiting." ; exit 1 ; }
3343
## Check if a given image exists in the current manifest docker-bake.hcl
34-
check_image = make --silent list | grep -w '$(1)' >/dev/null 2>&1 || { echo "Error: the image '$(1)' does not exist in manifest for the platform 'linux/$(ARCH)'. Please check the output of 'make list'. Exiting." ; exit 1 ; }
44+
check_image = make --silent list | grep -w '$(1)' >/dev/null 2>&1 || { echo "Error: the image '$(1)' does not exist in manifest for the current platform '$(OS)/$(ARCH)'. Please check the output of 'make list'. Exiting." ; exit 1 ; }
3545
## Base "docker buildx base" command to be reused everywhere
3646
bake_base_cli := docker buildx bake -f docker-bake.hcl --load
3747

@@ -70,38 +80,50 @@ hadolint:
7080
shellcheck:
7181
@$(ROOT_DIR)/tools/shellcheck -e SC1091 jenkins-support *.sh tests/test_helpers.bash tools/hadolint tools/shellcheck .ci/publish.sh
7282

73-
# Build targets depending on the current architecture
83+
# Build all targets with on the current OS and architecture
7484
build: check-reqs
75-
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' $(shell make --silent list)
85+
@set -x; $(bake_base_cli) --set '*.platform=$(OS)/$(ARCH)' $(shell make --silent list)
7686

77-
# Build targets depending on the architecture
87+
# Build targets depending on the architecture (Linux only, no multiarch for Windows)
7888
buildarch-%: check-reqs
7989
@$(bake_base_cli) --set '*.platform=linux/$*' $(shell make --silent listarch-$*)
8090

81-
# Build a specific target with the current architecture
91+
# Build a specific target with the current OS and architecture
8292
build-%: check-reqs
8393
@$(call check_image,$*)
84-
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' '$*'
94+
@set -x; $(bake_base_cli) --set '*.platform=$(OS)/$(ARCH)' '$*'
8595

8696
# Show all targets
8797
show:
88-
@$(bake_base_cli) --progress=quiet linux --print | jq
98+
@make show-all
8999

90-
# List all tags
100+
# Show a specific target
101+
show-%:
102+
@$(bake_base_cli) --progress=quiet '$*' --print | jq
103+
104+
# List tags of all targets
91105
tags:
92-
@make show | jq -r ' .target | to_entries[] | .key as $$name | .value.tags[] | "\(.) (\($$name))"' | LC_ALL=C sort -u
106+
@make tags-all
107+
108+
# List tags of a specific target
109+
tags-%:
110+
@make show-$* | jq -r ' .target | to_entries[] | .key as $$name | .value.tags[] | "\(.) (\($$name))"' | LC_ALL=C sort -u
93111

94-
# List all platforms
112+
# List tags of all targets
95113
platforms:
96-
@make show | jq -r ' .target | to_entries[] | .key as $$name | .value.platforms[] | "\($$name):\(.)"' | LC_ALL=C sort -u
114+
@make platforms-all
115+
116+
# List platforms of a specific target
117+
platforms-%:
118+
@make show-$* | jq -r ' .target | to_entries[] | .key as $$name | .value.platforms[] | "\($$name):\(.)"' | LC_ALL=C sort -u
97119

98-
# Return the list of targets depending on the current architecture
120+
# Return the list of targets depending on the current OS and architecture
99121
list: check-reqs
100-
@set -x; make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("linux/$(ARCH)"))?) | add'
122+
@set -x; make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("$(OS)/$(ARCH)"))?) | add'
101123

102-
# Return the list of targets depending on the architecture
124+
# Return the list of targets depending on the architecture (Linux only, no multiarch for Windows)
103125
listarch-%: check-reqs
104-
@make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("linux/$*"))?) | add'
126+
@set -x; make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("linux/$*"))?) | add'
105127

106128
# Ensure bats exists in the current folder
107129
bats:

build-windows.yaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

docker-bake.hcl

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ variable "RHEL_RELEASE_LINE" {
8383
default = "ubi9"
8484
}
8585

86+
# Set this value to a specific Windows version to override Windows versions to build returned by windowsversions function
87+
variable "WINDOWS_VERSION_OVERRIDE" {
88+
default = ""
89+
}
90+
8691
## Internal variables
8792
variable "jdk_versions" {
8893
default = {
@@ -165,6 +170,28 @@ target "rhel" {
165170
platforms = platforms(current_rhel, jdk)
166171
}
167172

173+
target "windowsservercore" {
174+
matrix = {
175+
jdk = jdks_to_build()
176+
windows_version = windowsversions("windowsservercore")
177+
}
178+
name = "windowsservercore_jdk${jdk}"
179+
dockerfile = "windows/windowsservercore/hotspot/Dockerfile"
180+
context = "."
181+
args = {
182+
JENKINS_VERSION = JENKINS_VERSION
183+
WAR_SHA = WAR_SHA
184+
WAR_URL = war_url()
185+
COMMIT_SHA = COMMIT_SHA
186+
PLUGIN_CLI_VERSION = PLUGIN_CLI_VERSION
187+
JAVA_VERSION = javaversion(jdk)
188+
JAVA_HOME = "C:/openjdk-${jdk}"
189+
WINDOWS_VERSION = windows_version
190+
}
191+
tags = windows_tags("windowsservercore-${windows_version}", jdk)
192+
platforms = ["windows/amd64"]
193+
}
194+
168195
## Groups
169196
group "linux" {
170197
targets = [
@@ -174,6 +201,19 @@ group "linux" {
174201
]
175202
}
176203

204+
group "windows" {
205+
targets = [
206+
"windowsservercore"
207+
]
208+
}
209+
210+
group "all" {
211+
targets = [
212+
"linux",
213+
"windows",
214+
]
215+
}
216+
177217
## Common functions
178218
# return true if JENKINS_VERSION is a Weekly (one sequence of digits with a trailing literal '.')
179219
function "is_jenkins_version_weekly" {
@@ -290,6 +330,25 @@ function "linux_tags" {
290330
)
291331
}
292332

333+
# Return an array of tags depending on the agent type, the jdk
334+
# and the flavor and version of Windows passed as parameters (ex: windowsservercore-ltsc2022)
335+
function "windows_tags" {
336+
params = [distribution, jdk]
337+
result = [
338+
## Always publish explicit jdk tag
339+
tag(true, "jdk${jdk}-hotspot-${distribution}"),
340+
tag_weekly(false, "jdk${jdk}-hotspot-${distribution}"),
341+
tag_lts(false, "lts-jdk${jdk}-hotspot-${distribution}"),
342+
343+
# ## Default JDK extra short tags
344+
is_default_jdk(jdk) ? tag(true, "hotspot-${distribution}") : "",
345+
is_default_jdk(jdk) ? tag_weekly(false, distribution) : "",
346+
is_default_jdk(jdk) ? tag_weekly(true, distribution) : "",
347+
is_default_jdk(jdk) ? tag_lts(false, "lts-${distribution}") : "",
348+
is_default_jdk(jdk) ? tag_lts(true, distribution) : "",
349+
]
350+
}
351+
293352
# Return if the distribution passed in parameter is Alpine
294353
function "is_alpine" {
295354
params = [distribution]
@@ -351,3 +410,11 @@ function "debian_tags" {
351410
is_default_jdk(jdk) ? tag_lts(true, slim_suffix(variant, "lts")) : "",
352411
]
353412
}
413+
414+
# Return array of Windows version(s) to build
415+
# Can be overriden by setting WINDOWS_VERSION_OVERRIDE to a specific Windows version
416+
# Ex: WINDOWS_VERSION_OVERRIDE=ltsc2025 docker buildx bake windows
417+
function "windowsversions" {
418+
params = [flavor]
419+
result = notequal(WINDOWS_VERSION_OVERRIDE, "") ? [WINDOWS_VERSION_OVERRIDE] : ["ltsc2022"]
420+
}

0 commit comments

Comments
 (0)