From f21081d35e8f133069e203fd4f5415cb73c0c390 Mon Sep 17 00:00:00 2001 From: Matthew DeVenny Date: Mon, 23 Sep 2024 14:49:11 -0700 Subject: [PATCH] Add regctl promotion to accelerate image promotion Signed-off-by: Matthew DeVenny --- .../pipeline/promote/BoxPromote.groovy | 100 +++++++++++++----- 1 file changed, 72 insertions(+), 28 deletions(-) diff --git a/src/com/boxboat/jenkins/pipeline/promote/BoxPromote.groovy b/src/com/boxboat/jenkins/pipeline/promote/BoxPromote.groovy index cd27758..81353ad 100644 --- a/src/com/boxboat/jenkins/pipeline/promote/BoxPromote.groovy +++ b/src/com/boxboat/jenkins/pipeline/promote/BoxPromote.groovy @@ -235,46 +235,90 @@ class BoxPromote extends BoxBase implements Serializable { refTag = "latest" } - config.images.each { image -> - promoteFromRegistry.withCredentials { - image.pull() - } + String result = Config.pipeline.sh(returnStdout: true, script: """regctl version || echo 'No regctl - using docker' """)?.trim() + if (result.contains("No regctl - using docker")) { + config.images.each { image -> + promoteFromRegistry.withCredentials { + image.pull() + } - imageSummary += "\n${image.path} promoted" - imageSummary += "\n\tfrom ${formatImageSummary(image, promotion.event, promoteFromRegistry)}" + imageSummary += "\n${image.path} promoted" + imageSummary += "\n\tfrom ${formatImageSummary(image, promotion.event, promoteFromRegistry)}" - pushRegistries.each { pushRegistry -> - def newImageSemVer = image.copy() - newImageSemVer.host = pushRegistry.host - newImageSemVer.namespace = pushRegistry.namespace - newImageSemVer.tag = promoteVersionString + pushRegistries.each { pushRegistry -> + def newImageSemVer = image.copy() + newImageSemVer.host = pushRegistry.host + newImageSemVer.namespace = pushRegistry.namespace + newImageSemVer.tag = promoteVersionString - def newImageRef + def newImageRef - // Don't push a reftag if we are not writing back - if (writebackBuildVersions) { - newImageRef = image.copy() - newImageRef.tag = refTag - image.reTag(newImageRef) - } + // Don't push a reftag if we are not writing back + if (writebackBuildVersions) { + newImageRef = image.copy() + newImageRef.tag = refTag + image.reTag(newImageRef) + } - image.reTag(newImageSemVer) + image.reTag(newImageSemVer) + + pushRegistry.withCredentials { + newImageSemVer.push() + if (newImageRef) { + newImageRef.push() + } + } + + imageSummary += "\n\tto ${formatImageSummary(newImageSemVer, promotion.promoteToEvent, pushRegistry)}" - pushRegistry.withCredentials { - newImageSemVer.push() if (newImageRef) { - newImageRef.push() + imageSummary += "\n\t ${formatImageSummary(newImageRef, promotion.promoteToEvent, pushRegistry)}" } } + if (writebackBuildVersions) { + buildVersions.setEventImageVersion(pushEvent, image, promoteVersionString, metadata) + } + } + } else { + config.images.each { image -> + imageSummary += "\n${image.path} promoted" + imageSummary += "\n\tfrom ${formatImageSummary(image, promotion.event, promoteFromRegistry)}" + + pushRegistries.each { pushRegistry -> + def newImageSemVer = image.copy() + newImageSemVer.host = pushRegistry.host + newImageSemVer.namespace = pushRegistry.namespace + newImageSemVer.tag = promoteVersionString + + def newImageRef + + // Don't push a reftag if we are not writing back + if (writebackBuildVersions) { + newImageRef = image.copy() + newImageRef.tag = refTag + + pushRegistry.withCredentials { + Config.pipeline.sh """ + regctl image copy ${image.getUrl()} ${newImageRef.getUrl()} + """ + } + } + + pushRegistry.withCredentials { + Config.pipeline.sh """ + regctl image copy ${image.getUrl()} ${newImageSemVer.getUrl()} + """ + } - imageSummary += "\n\tto ${formatImageSummary(newImageSemVer, promotion.promoteToEvent, pushRegistry)}" + imageSummary += "\n\tto ${formatImageSummary(newImageSemVer, promotion.promoteToEvent, pushRegistry)}" - if (newImageRef) { - imageSummary += "\n\t ${formatImageSummary(newImageRef, promotion.promoteToEvent, pushRegistry)}" + if (newImageRef) { + imageSummary += "\n\t ${formatImageSummary(newImageRef, promotion.promoteToEvent, pushRegistry)}" + } + } + if (writebackBuildVersions) { + buildVersions.setEventImageVersion(pushEvent, image, promoteVersionString, metadata) } - } - if (writebackBuildVersions) { - buildVersions.setEventImageVersion(pushEvent, image, promoteVersionString, metadata) } } if (writebackBuildVersions) {