Skip to content

Commit 8cf2e4a

Browse files
authored
Merge pull request #1121 from ravanelli/pr/manifest_tag
jobs/build-node-image: Add a tag field for the staging repo
2 parents 6c71aaa + 09d20c4 commit 8cf2e4a

File tree

2 files changed

+52
-38
lines changed

2 files changed

+52
-38
lines changed

jobs/build-node-image.Jenkinsfile

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,19 @@ lock(resource: "build-node-image") {
6666
def archinfo = arches.collectEntries{[it, [:]]}
6767
def now = java.time.LocalDateTime.now()
6868
def timestamp = now.format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm"))
69-
def (container_registry_staging_repo, container_registry_repo, prod_tags) = pipeutils.get_ocp_node_registry_repo(pipecfg, params.RELEASE, timestamp)
70-
def container_registry_staging_manifest_tag = "${params.RELEASE}"
71-
def container_registry_staging_image_tag = "${params.RELEASE}"
72-
def container_registry_staging_manifest = "${container_registry_staging_repo}:${container_registry_staging_manifest_tag}"
69+
def (registry_staging_repo, registry_staging_tags, registry_prod_repo, registry_prod_tags) = pipeutils.get_ocp_node_registry_repo(pipecfg, params.RELEASE, timestamp)
70+
71+
// `staging_tags` is a list to stay consistent with the `prod` objects,
72+
// but we only need a single tag here since it's used solely for storing
73+
// intermediary images before they are referenced in a multi-arch manifest.
74+
def registry_staging_tag = registry_staging_tags[0]
7375

7476
// add any additional root CA cert before we do anything that fetches
7577
pipeutils.addOptionalRootCA()
7678

7779
def yumrepos_file
80+
def node_image_manifest_digest
81+
def extensions_image_manifest_digest
7882
stage('Init') {
7983
shwrap("git clone ${stream_info.yumrepo.url} yumrepos")
8084
for (repo in stream_info.yumrepo.files) {
@@ -85,18 +89,15 @@ lock(resource: "build-node-image") {
8589
archiveArtifacts 'all.repo'
8690
}
8791

88-
if (params.PIPECFG_HOTFIX_REPO || params.PIPECFG_HOTFIX_REF) {
89-
container_registry_staging_image_tag += "-hotfix-${pipecfg.hotfix.name}"
90-
}
9192
stage('Build Node Image') {
9293
withCredentials([file(credentialsId: 'oscontainer-push-registry-secret', variable: 'REGISTRY_AUTH_FILE')]) {
9394
def build_from = params.FROM ?: stream_info.from
94-
pipeutils.build_and_push_image(arches: arches,
95+
node_image_manifest_digest = pipeutils.build_and_push_image(arches: arches,
9596
src_commit: commit,
9697
src_url: src_config_url,
97-
staging_repository: container_registry_staging_repo,
98-
image_tag_staging: container_registry_staging_image_tag,
99-
manifest_tag_staging: container_registry_staging_manifest_tag,
98+
staging_repository: registry_staging_repo,
99+
image_tag_staging: registry_staging_tag,
100+
manifest_tag_staging: "${registry_staging_tag}",
100101
secret: "id=yumrepos,src=${yumrepos_file}", // notsecret (for secret scanners)
101102
from: build_from,
102103
extra_build_args: ["--security-opt label=disable", "--mount-host-ca-certs", "--force"])
@@ -105,13 +106,13 @@ lock(resource: "build-node-image") {
105106
stage('Build Extensions Image') {
106107
withCredentials([file(credentialsId: 'oscontainer-push-registry-secret', variable: 'REGISTRY_AUTH_FILE')]) {
107108
// Use the node image as from
108-
def build_from = container_registry_staging_manifest
109-
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,
110111
src_commit: commit,
111112
src_url: src_config_url,
112-
staging_repository: container_registry_staging_repo,
113-
image_tag_staging: "${container_registry_staging_image_tag}-extensions",
114-
manifest_tag_staging: "${container_registry_staging_manifest_tag}-extensions",
113+
staging_repository: registry_staging_repo,
114+
image_tag_staging: "${registry_staging_tag}-extensions",
115+
manifest_tag_staging: "${registry_staging_tag}-extensions",
115116
secret: "id=yumrepos,src=${yumrepos_file}", // notsecret (for secret scanners)
116117
from: build_from,
117118
extra_build_args: ["--security-opt label=disable", "--mount-host-ca-certs",
@@ -123,16 +124,17 @@ lock(resource: "build-node-image") {
123124
// copy the extensions first as the node image existing is a signal
124125
// that it's ready for release. So we want all the expected artifacts
125126
// to be available when the ART tooling kicks in.
126-
for ( tag in prod_tags ) {
127-
pipeutils.copy_image("${container_registry_staging_manifest}-extensions",
128-
"${container_registry_repo}:${tag}-extensions")
129-
}
130127

131128
// Skopeo does not support pushing multiple tags at the same time
132129
// So we just recopy the same image multiple times.
133130
// https://github.com/containers/skopeo/issues/513
134-
for (tag in prod_tags) {
135-
pipeutils.copy_image(container_registry_staging_manifest, "${container_registry_repo}:${tag}")
131+
for (tag in registry_prod_tags) {
132+
pipeutils.copy_image("${registry_staging_repo}@${extensions_image_manifest_digest}",
133+
"${registry_prod_repo}:${tag}-extensions")
134+
}
135+
for (tag in registry_prod_tags) {
136+
pipeutils.copy_image("${registry_staging_repo}@${node_image_manifest_digest}",
137+
"${registry_prod_repo}:${tag}")
136138
}
137139
}
138140
}

utils.groovy

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -551,22 +551,25 @@ def get_registry_repos(pipecfg, stream, version) {
551551
}
552552

553553
def get_ocp_node_registry_repo(pipecfg, release, timestamp) {
554-
def staging_repo = pipecfg.ocp_node_builds.registries.staging
555-
def repo = pipecfg.ocp_node_builds.registries.prod.image
556-
def tags = pipecfg.ocp_node_builds.registries.prod.tags
557-
558-
processed_tags = []
559-
for (tag in tags) {
560-
tag = utils.substituteStr(tag, [RELEASE: release, TIMESTAMP: timestamp])
561-
if (pipecfg.hotfix) {
562-
// this is a hotfix build; include the hotfix name
563-
// in the tag suffix so we don't clobber official
564-
// tags
565-
tag += "-hotfix-${pipecfg.hotfix.name}"
554+
def staging_repo = pipecfg.ocp_node_builds.registries.staging.image
555+
def staging_manifest_tags = pipecfg.ocp_node_builds.registries.staging.tags
556+
def prod_repo = pipecfg.ocp_node_builds.registries.prod.image
557+
def prod_tags = pipecfg.ocp_node_builds.registries.prod.tags
558+
def processTags = { tagList ->
559+
tagList.collect { tag ->
560+
def substituted = utils.substituteStr(tag, [RELEASE: release, TIMESTAMP: timestamp])
561+
if (pipecfg.hotfix) {
562+
// this is a hotfix build; include the hotfix name
563+
// in the tag suffix so we don't clobber official
564+
// tags
565+
substituted += "-hotfix-${pipecfg.hotfix.name}"
566+
}
567+
return substituted
566568
}
567-
processed_tags += tag
568569
}
569-
return [staging_repo, repo, processed_tags]
570+
def final_staging_manifest_tags = processTags(staging_manifest_tags)
571+
def final_prod_tags = processTags(prod_tags)
572+
return [staging_repo, final_staging_manifest_tags, prod_repo, final_prod_tags]
570573
}
571574

572575
// Determine if the config.yaml has a test_architectures entry for
@@ -870,15 +873,22 @@ def push_manifest(digests, repo, manifest_tag) {
870873
for (digest in digests) {
871874
images += " --image=docker://${repo}@${digest}"
872875
}
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]
873880
// arbitrarily selecting the s390x builder; we don't run this
874881
// locally because podman wants user namespacing (yes, even just
875882
// to push a manifest...)
876883
pipeutils.withPodmanRemoteArchBuilder(arch: "s390x") {
877884
shwrap("""
878885
cosa push-container-manifest \
879-
--tag ${manifest_tag} --repo ${repo} ${images}
886+
--tag ${manifest_tag} --repo ${repo} ${images} ${push_args.join(' ')}
880887
""")
881888
}
889+
digest = readFile(digest_file)
890+
shwrap("rm ${digest_file}")
891+
return digest
882892
}
883893

884894
def copy_image(src_image, dest_image, authfile = "") {
@@ -922,13 +932,15 @@ def build_and_push_image(params = [:]) {
922932

923933
def secret = params.get('secret', "");
924934
def from = params.get('from', "");
935+
def manifest_digest = ""
925936
def extra_build_args = params.get('extra_build_args', "");
926937

927938
def digests = build_remote_image(params['arches'], params['src_commit'], params['src_url'], params['staging_repository'],
928939
params['image_tag_staging'], secret, from, extra_build_args)
929940
stage("Push Manifest") {
930-
push_manifest(digests, params['staging_repository'], params['manifest_tag_staging'])
941+
manifest_digest = push_manifest(digests, params['staging_repository'], params['manifest_tag_staging'])
931942
}
943+
return manifest_digest
932944
}
933945

934946
return this

0 commit comments

Comments
 (0)