Skip to content

Commit 9ddd504

Browse files
authored
chore: show docker bake args and targets before publication (#2211)
1 parent 23db2d9 commit 9ddd504

File tree

3 files changed

+122
-10
lines changed

3 files changed

+122
-10
lines changed

.ci/publish.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set -eu -o pipefail
1111

1212
: "${DOCKERHUB_ORGANISATION:=jenkins}"
1313
: "${DOCKERHUB_REPO:=jenkins}"
14+
: "${BAKE_TARGET:=linux}"
1415

1516
export JENKINS_REPO="${DOCKERHUB_ORGANISATION}/${DOCKERHUB_REPO}"
1617

@@ -78,14 +79,15 @@ fi
7879
build_opts=("--pull")
7980
metadata_suffix="publish"
8081
if test "${dry_run}" == "true"; then
81-
build_opts+=("--load")
82+
build_opts+=("--set=*.output=type=cacheonly")
8283
metadata_suffix="dry-run"
8384
else
8485
build_opts+=("--push")
8586
fi
8687

8788
# Save build result metadata
88-
BUILD_METADATA_PATH="target/build-result-metadata_${metadata_suffix}.json"
89+
mkdir -p target
90+
BUILD_METADATA_PATH="target/build-result-metadata_${BAKE_TARGET}_${metadata_suffix}.json"
8991
build_opts+=("--metadata-file=${BUILD_METADATA_PATH}")
9092

9193
WAR_SHA="$(curl --disable --fail --silent --show-error --location "https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war.sha256")"
@@ -101,6 +103,12 @@ Using the following settings:
101103
* LATEST_WEEKLY: ${LATEST_WEEKLY}
102104
* LATEST_LTS: ${LATEST_LTS}
103105
* BUILD_METADATA_PATH: ${BUILD_METADATA_PATH}
106+
* BAKE_TARGET: ${BAKE_TARGET}
107+
* BAKE OPTIONS:
108+
$(printf ' %s\n' "${build_opts[@]}")
109+
110+
* RESOLVED BAKE CONFIG:
111+
$(docker buildx bake --file docker-bake.hcl --print "${BAKE_TARGET}")
104112
EOF
105113

106-
docker buildx bake --file docker-bake.hcl "${build_opts[@]}" linux
114+
docker buildx bake --file docker-bake.hcl "${build_opts[@]}" "${BAKE_TARGET}"

HACKING.adoc

Lines changed: 106 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,116 @@ In order to debug the controller, use the `-e DEBUG=true -p 5005:5005` when star
149149
Jenkins will be suspended on the startup in such case,
150150
and then it will be possible to attach a debugger from IDE to it.
151151

152-
== Test the publishing using an overridden target repository on Docker Hub
152+
== Test images publication
153153

154-
Create a new dedicated target repository in your Docker Hub account, and use it like follows:
154+
You can test the script used for publication in dry-run by setting an existing Jenkins Core version and by passing the `-n` option:
155155

156156
[source,bash]
157157
--
158-
export DOCKERHUB_ORGANISATION=batmat
159-
export DOCKERHUB_REPO=test-jenkins
158+
$ export JENKINS_VERSION=2.528.3
159+
$ ./.ci/publish.sh -n
160+
Dry run, will not publish images
161+
Using the following settings:
162+
* JENKINS_REPO: jenkins/jenkins
163+
* JENKINS_VERSION: 2.528.3
164+
* WAR_SHA: bfa31f1e3aacebb5bce3d5076c73df97bf0c0567eeb8d8738f54f6bac48abd74
165+
* COMMIT_SHA: 1c72a9383191562eb3c44838aeeadad0839c2c92
166+
* LATEST_WEEKLY: false
167+
* LATEST_LTS: true
168+
* BUILD_METADATA_PATH: target/build-result-metadata_linux_dry-run.json
169+
[+] Building 104.6s (59/73)
170+
<...snip...>
171+
--
172+
173+
Note that if you can set `BAKE_TARGET` to test the publication of a single target instead the default "linux" multiarch (heavy) build:
174+
175+
[source,bash]
176+
--
177+
$ export BAKE_TARGET=debiand_jdk25
178+
$ ./.ci/publish.sh -n
179+
Using the following settings:
180+
* JENKINS_REPO: jenkins/jenkins
181+
* JENKINS_VERSION: 2.528.3
182+
* WAR_SHA: bfa31f1e3aacebb5bce3d5076c73df97bf0c0567eeb8d8738f54f6bac48abd74
183+
* COMMIT_SHA: aaf4e7faf887b7ac4879c3bf540ede48220cca9f
184+
* LATEST_WEEKLY: false
185+
* LATEST_LTS: true
186+
* BUILD_METADATA_PATH: target/build-result-metadata_debian_jdk25_dry-run.json
187+
* BAKE TARGET: debian_jdk25
188+
* BUILDX OPTIONS:
189+
--pull
190+
--set=*.output=type=cacheonly
191+
--metadata-file=target/build-result-metadata_debian_jdk25_dry-run.json
192+
193+
* RESOLVED BAKE CONFIG:
194+
{
195+
"group": {
196+
"default": {
197+
"targets": [
198+
"debian_jdk25"
199+
]
200+
}
201+
},
202+
"target": {
203+
"debian_jdk25": {
204+
"context": ".",
205+
"dockerfile": "debian/Dockerfile",
206+
"args": {
207+
"COMMIT_SHA": "aaf4e7faf887b7ac4879c3bf540ede48220cca9f",
208+
"DEBIAN_RELEASE_LINE": "trixie",
209+
"DEBIAN_VARIANT": "",
210+
"DEBIAN_VERSION": "20251117",
211+
"JAVA_VERSION": "25.0.1_8",
212+
"JENKINS_VERSION": "2.528.3",
213+
"PLUGIN_CLI_VERSION": "2.13.2",
214+
"WAR_SHA": "bfa31f1e3aacebb5bce3d5076c73df97bf0c0567eeb8d8738f54f6bac48abd74",
215+
"WAR_URL": "https://get.jenkins.io/war-stable/2.528.3/jenkins.war"
216+
},
217+
"tags": [
218+
"docker.io/jenkins/jenkins:2.528.3-jdk25",
219+
"docker.io/jenkins/jenkins:lts-jdk25",
220+
"docker.io/jenkins/jenkins:2.528.3-lts-jdk25"
221+
],
222+
"platforms": [
223+
"linux/amd64",
224+
"linux/arm64",
225+
"linux/s390x",
226+
"linux/ppc64le"
227+
]
228+
}
229+
}
230+
}
231+
[+] Building 104.6s (59/73)
232+
...
233+
--
234+
235+
You can also pass the `-d` option (debug) to see traces from the script.
236+
237+
=== Using an overridden target repository on Docker Hub
238+
239+
Create a new dedicated target repository in your Docker Hub account, and use it like follows (note the absence of `-d` option):
240+
241+
[source,bash]
242+
--
243+
$ export DOCKERHUB_ORGANISATION=jenkins4eval
244+
$ export DOCKERHUB_REPO=test-jenkins
160245
# The log below will help confirm this override was taken in account:
161-
./publish.sh
162-
Docker repository in Use:
163-
* JENKINS_REPO: batmat/test-jenkins
246+
$ ./.ci/publish.sh
247+
Using the following settings:
248+
* JENKINS_REPO: jenkins4eval/test-jenkins
249+
* JENKINS_VERSION: 2.528.3
250+
* WAR_SHA: bfa31f1e3aacebb5bce3d5076c73df97bf0c0567eeb8d8738f54f6bac48abd74
251+
* COMMIT_SHA: aaf4e7faf887b7ac4879c3bf540ede48220cca9f
252+
* LATEST_WEEKLY: false
253+
* LATEST_LTS: true
254+
* BUILD_METADATA_PATH: target/build-result-metadata_linux_publish.json
255+
* BAKE TARGET: linux
256+
* BUILDX OPTIONS:
257+
--pull
258+
--push
259+
--metadata-file=target/build-result-metadata_linux_publish.json
260+
261+
* RESOLVED BAKE CONFIG:
262+
{
164263
...
165264
--

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,13 @@ test: prepare-test
186186
@make --silent list | while read image; do make --silent "test-$${image}"; done
187187

188188
# Set all required variables and publish all targets
189+
# Calling publish.sh with `-n` (dry-run) arg in case `PUBLISH` is not set to true
189190
publish: target
191+
ifeq ($(PUBLISH),true)
190192
./.ci/publish.sh
193+
else
194+
./.ci/publish.sh -n
195+
endif
191196

192197
clean:
193198
rm -rf tests/test_helper/bats-*; \

0 commit comments

Comments
 (0)