Skip to content

Commit

Permalink
Add regctl promotion to accelerate image promotion
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew DeVenny <[email protected]>
  • Loading branch information
matthewdevenny committed Sep 23, 2024
1 parent bf939fd commit f21081d
Showing 1 changed file with 72 additions and 28 deletions.
100 changes: 72 additions & 28 deletions src/com/boxboat/jenkins/pipeline/promote/BoxPromote.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -235,46 +235,90 @@ class BoxPromote extends BoxBase<PromoteConfig> 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) {
Expand Down

0 comments on commit f21081d

Please sign in to comment.