Skip to content

Commit bb0fa3c

Browse files
authored
chore(pipeline/multiarch): don't rebuild images of architectures already built elsewhere (#2155)
1 parent 1a6e44b commit bb0fa3c

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

Jenkinsfile

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ properties(listOfProperties)
1414
// Default environment variable set to allow images publication
1515
def envVars = ['PUBLISH=true']
1616

17+
// List of architectures and corresponding ci.jenkins.io agent labels
18+
def architecturesAndCiJioAgentLabels = [
19+
'amd64': 'docker && amd64',
20+
'arm64': 'arm64docker',
21+
// No corresponding agent, using qemu
22+
'ppc64le': 'docker && amd64',
23+
's390x': 's390xdocker',
24+
]
25+
1726
// Set to true in a replay to simulate a LTS build on ci.jenkins.io
1827
// It will set the environment variables needed for a LTS
1928
// and disable images publication out of caution
@@ -118,7 +127,7 @@ stage('Build') {
118127
def imageToBuild = i
119128

120129
builds[imageToBuild] = {
121-
nodeWithTimeout('docker') {
130+
nodeWithTimeout(architecturesAndCiJioAgentLabels["amd64"]) {
122131
deleteDir()
123132

124133
stage('Checkout') {
@@ -153,20 +162,19 @@ stage('Build') {
153162
}
154163
}
155164
}
156-
builds['multiarch-build'] = {
157-
nodeWithTimeout('docker') {
158-
stage('Checkout') {
159-
deleteDir()
160-
checkout scm
161-
}
162-
163-
// sanity check that proves all images build on declared platforms
164-
stage('Multi arch build') {
165-
infra.withDockerCredentials {
166-
sh '''
167-
make docker-init
168-
docker buildx bake --file docker-bake.hcl linux
169-
'''
165+
// Building every other architectures than amd64 on agents with the corresponding labels if available
166+
architecturesAndCiJioAgentLabels.findAll { arch, _ -> arch != 'amd64' }.each { architecture, labels ->
167+
builds[architecture] = {
168+
nodeWithTimeout(labels) {
169+
stage('Checkout') {
170+
deleteDir()
171+
checkout scm
172+
}
173+
// sanity check that proves all images build on declared platforms not already built in other stages
174+
stage("Multi arch build - ${architecture}") {
175+
infra.withDockerCredentials {
176+
sh "make docker-init listarch-${architecture} buildarch-${architecture}"
177+
}
170178
}
171179
}
172180
}

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ endif
5757
else
5858
docker buildx create --use --bootstrap --driver docker-container
5959
endif
60+
# There is only an amd64 qemu image
61+
ifeq ($(ARCH),amd64)
6062
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
63+
endif
6164

6265
# Lint check on all Dockerfiles
6366
hadolint:
@@ -71,6 +74,10 @@ shellcheck:
7174
build: check-reqs
7275
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' $(shell make --silent list)
7376

77+
# Build targets depending on the architecture
78+
buildarch-%: check-reqs
79+
@$(bake_base_cli) --set '*.platform=linux/$*' $(shell make --silent listarch-$*)
80+
7481
# Build a specific target with the current architecture
7582
build-%: check-reqs
7683
@$(call check_image,$*)
@@ -92,6 +99,10 @@ platforms:
9299
list: check-reqs
93100
@set -x; make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("linux/$(ARCH)"))?) | add'
94101

102+
# Return the list of targets depending on the architecture
103+
listarch-%: check-reqs
104+
@make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("linux/$*"))?) | add'
105+
95106
# Ensure bats exists in the current folder
96107
bats:
97108
git clone https://github.com/bats-core/bats-core bats ;\

0 commit comments

Comments
 (0)