Skip to content

Commit faeb3fe

Browse files
authored
chore: store docker build result metadata (#2205)
1 parent 9cb934d commit faeb3fe

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

.ci/publish.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,21 @@ else
7676
fi
7777

7878
build_opts=("--pull")
79+
metadata_suffix="publish"
7980
if test "${dry_run}" == "true"; then
8081
build_opts+=("--load")
82+
metadata_suffix="dry-run"
8183
else
8284
build_opts+=("--push")
8385
fi
8486

87+
# Save build result metadata
88+
BUILD_METADATA_PATH="target/build-result-metadata_${metadata_suffix}.json"
89+
build_opts+=("--metadata-file=${BUILD_METADATA_PATH}")
90+
8591
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")"
8692
COMMIT_SHA=$(git rev-parse HEAD)
87-
export COMMIT_SHA JENKINS_VERSION WAR_SHA LATEST_WEEKLY LATEST_LTS
93+
export COMMIT_SHA JENKINS_VERSION WAR_SHA LATEST_WEEKLY LATEST_LTS BUILD_METADATA_PATH
8894

8995
cat <<EOF
9096
Using the following settings:
@@ -94,6 +100,7 @@ Using the following settings:
94100
* COMMIT_SHA: ${COMMIT_SHA}
95101
* LATEST_WEEKLY: ${LATEST_WEEKLY}
96102
* LATEST_LTS: ${LATEST_LTS}
103+
* BUILD_METADATA_PATH: ${BUILD_METADATA_PATH}
97104
EOF
98105

99106
docker buildx bake --file docker-bake.hcl "${build_opts[@]}" linux

Jenkinsfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ stage('Build') {
149149
stage("Build linux-${imageToBuild}") {
150150
infra.withDockerCredentials {
151151
sh "make build-${imageToBuild}"
152+
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
152153
}
153154
}
154155

@@ -179,6 +180,7 @@ stage('Build') {
179180
stage("Multi arch build - ${architecture}") {
180181
infra.withDockerCredentials {
181182
sh "make docker-init buildarch-${architecture}"
183+
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
182184
}
183185
}
184186
}
@@ -206,6 +208,7 @@ stage('Build') {
206208
infra.withDockerCredentials {
207209
sh 'make docker-init'
208210
sh 'make publish'
211+
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
209212
}
210213
}
211214
}

Makefile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ check_cli = type "$(1)" >/dev/null 2>&1 || { echo "Error: command '$(1)' require
3434
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 ; }
3535
## Base "docker buildx base" command to be reused everywhere
3636
bake_base_cli := docker buildx bake -f docker-bake.hcl --load
37+
## Default bake target
38+
bake_default_target := linux
3739

3840
check-reqs:
3941
## Build requirements
@@ -71,21 +73,21 @@ shellcheck:
7173
@$(ROOT_DIR)/tools/shellcheck -e SC1091 jenkins-support *.sh tests/test_helpers.bash tools/hadolint tools/shellcheck .ci/publish.sh
7274

7375
# Build targets depending on the current architecture
74-
build: check-reqs
75-
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' $(shell make --silent list)
76+
build: check-reqs target
77+
@set -x; $(bake_base_cli) --metadata-file=target/build-result-metadata_$(bake_default_target).json --set '*.platform=linux/$(ARCH)' $(shell make --silent list)
7678

7779
# Build targets depending on the architecture
78-
buildarch-%: check-reqs showarch-%
79-
@set -x; $(bake_base_cli) --set '*.platform=linux/$*' $(shell make --silent listarch-$*)
80+
buildarch-%: check-reqs target showarch-%
81+
@set -x; $(bake_base_cli) --metadata-file=target/build-result-metadata_$*.json --set '*.platform=linux/$*' $(shell make --silent listarch-$*)
8082

8183
# Build a specific target with the current architecture
82-
build-%: check-reqs show-%
84+
build-%: check-reqs target show-%
8385
@$(call check_image,$*)
84-
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' '$*'
86+
@set -x; $(bake_base_cli) --metadata-file=target/build-result-metadata_$*.json --set '*.platform=linux/$(ARCH)' '$*'
8587

8688
# Show all targets
8789
show:
88-
@set -x; make --silent show-linux
90+
@set -x; make --silent show-$(bake_default_target)
8991

9092
# Show a specific target
9193
show-%:
@@ -117,9 +119,12 @@ bats:
117119
cd bats ;\
118120
git checkout 3bca150ec86275d6d9d5a4fd7d48ab8b6c6f3d87; # v1.13.0
119121

120-
# Ensure all bats submodules are up to date and that the tests target folder exists
121-
prepare-test: bats check-reqs
122+
# Ensure all bats submodules are up to date
123+
prepare-test: bats check-reqs target
122124
git submodule update --init --recursive
125+
126+
# Ensure tests and build metadata "target" folder exist
127+
target:
123128
mkdir -p target
124129

125130
## Define bats options based on environment
@@ -159,7 +164,7 @@ test: prepare-test
159164
@make --silent list | while read image; do make --silent "test-$${image}"; done
160165

161166
# Set all required variables and publish all targets
162-
publish:
167+
publish: target
163168
./.ci/publish.sh
164169

165170
clean:

0 commit comments

Comments
 (0)