Skip to content

Commit 09d20c4

Browse files
jbtrystramravanelli
andcommitted
jobs/node-image-build: Use manifest digests instead of tags when pushing
Retrieve the digests of intermediary manifests instead of relying on the tags they were pushed with. This prevents accidentally referencing stale manifests that may still exist locally on the builders from previous runs. We were already using digests for the images within the manifests, so this also improves overall consistency. Co-authored-by: Renata Ravanelli <[email protected]>
1 parent 8e3d962 commit 09d20c4

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

jobs/build-node-image.Jenkinsfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ lock(resource: "build-node-image") {
7777
pipeutils.addOptionalRootCA()
7878

7979
def yumrepos_file
80+
def node_image_manifest_digest
81+
def extensions_image_manifest_digest
8082
stage('Init') {
8183
shwrap("git clone ${stream_info.yumrepo.url} yumrepos")
8284
for (repo in stream_info.yumrepo.files) {
@@ -90,7 +92,7 @@ lock(resource: "build-node-image") {
9092
stage('Build Node Image') {
9193
withCredentials([file(credentialsId: 'oscontainer-push-registry-secret', variable: 'REGISTRY_AUTH_FILE')]) {
9294
def build_from = params.FROM ?: stream_info.from
93-
pipeutils.build_and_push_image(arches: arches,
95+
node_image_manifest_digest = pipeutils.build_and_push_image(arches: arches,
9496
src_commit: commit,
9597
src_url: src_config_url,
9698
staging_repository: registry_staging_repo,
@@ -104,8 +106,8 @@ lock(resource: "build-node-image") {
104106
stage('Build Extensions Image') {
105107
withCredentials([file(credentialsId: 'oscontainer-push-registry-secret', variable: 'REGISTRY_AUTH_FILE')]) {
106108
// Use the node image as from
107-
def build_from = "${registry_staging_repo}:${registry_staging_tag}"
108-
pipeutils.build_and_push_image(arches: arches,
109+
def build_from = "${registry_staging_repo}@${node_image_manifest_digest}"
110+
extensions_image_manifest_digest = pipeutils.build_and_push_image(arches: arches,
109111
src_commit: commit,
110112
src_url: src_config_url,
111113
staging_repository: registry_staging_repo,
@@ -127,11 +129,11 @@ lock(resource: "build-node-image") {
127129
// So we just recopy the same image multiple times.
128130
// https://github.com/containers/skopeo/issues/513
129131
for (tag in registry_prod_tags) {
130-
pipeutils.copy_image("${registry_staging_repo}:${registry_staging_tag}-extensions",
132+
pipeutils.copy_image("${registry_staging_repo}@${extensions_image_manifest_digest}",
131133
"${registry_prod_repo}:${tag}-extensions")
132134
}
133135
for (tag in registry_prod_tags) {
134-
pipeutils.copy_image("${registry_staging_repo}:${registry_staging_tag}",
136+
pipeutils.copy_image("${registry_staging_repo}@${node_image_manifest_digest}",
135137
"${registry_prod_repo}:${tag}")
136138
}
137139
}

utils.groovy

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,15 +873,22 @@ def push_manifest(digests, repo, manifest_tag) {
873873
for (digest in digests) {
874874
images += " --image=docker://${repo}@${digest}"
875875
}
876+
def digest = ""
877+
def digest_file = "${manifest_tag}.digestfile"
878+
// save the digest to a file named after the tag we are pushing
879+
push_args = ["--write-digest-to-file", digest_file]
876880
// arbitrarily selecting the s390x builder; we don't run this
877881
// locally because podman wants user namespacing (yes, even just
878882
// to push a manifest...)
879883
pipeutils.withPodmanRemoteArchBuilder(arch: "s390x") {
880884
shwrap("""
881885
cosa push-container-manifest \
882-
--tag ${manifest_tag} --repo ${repo} ${images}
886+
--tag ${manifest_tag} --repo ${repo} ${images} ${push_args.join(' ')}
883887
""")
884888
}
889+
digest = readFile(digest_file)
890+
shwrap("rm ${digest_file}")
891+
return digest
885892
}
886893

887894
def copy_image(src_image, dest_image, authfile = "") {
@@ -925,13 +932,15 @@ def build_and_push_image(params = [:]) {
925932

926933
def secret = params.get('secret', "");
927934
def from = params.get('from', "");
935+
def manifest_digest = ""
928936
def extra_build_args = params.get('extra_build_args', "");
929937

930938
def digests = build_remote_image(params['arches'], params['src_commit'], params['src_url'], params['staging_repository'],
931939
params['image_tag_staging'], secret, from, extra_build_args)
932940
stage("Push Manifest") {
933-
push_manifest(digests, params['staging_repository'], params['manifest_tag_staging'])
941+
manifest_digest = push_manifest(digests, params['staging_repository'], params['manifest_tag_staging'])
934942
}
943+
return manifest_digest
935944
}
936945

937946
return this

0 commit comments

Comments
 (0)