-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: package aliases for snapshots #21960
Changes from all commits
3cd405d
707e0d7
cff2cef
843f472
64949ff
d2a3f39
4724960
7416af7
e8ab32b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,10 +191,14 @@ def pushCIDockerImages(){ | |
} | ||
} | ||
|
||
def tagAndPush(name){ | ||
def tagAndPush(beatName){ | ||
def libbetaVer = sh(label: 'Get libbeat version', script: 'grep defaultBeatVersion ${BASE_DIR}/libbeat/version/version.go|cut -d "=" -f 2|tr -d \\"', returnStdout: true)?.trim() | ||
def aliasVersion = "" | ||
if("${env.SNAPSHOT}" == "true"){ | ||
aliasVersion = libbetaVer.substring(0, libbetaVer.lastIndexOf(".")) // remove third number in version | ||
|
||
libbetaVer += "-SNAPSHOT" | ||
aliasVersion += "-SNAPSHOT" | ||
} | ||
|
||
def tagName = "${libbetaVer}" | ||
|
@@ -207,25 +211,37 @@ def tagAndPush(name){ | |
// supported image flavours | ||
def variants = ["", "-oss", "-ubi8"] | ||
variants.each { variant -> | ||
def oldName = "${DOCKER_REGISTRY}/beats/${name}${variant}:${libbetaVer}" | ||
def newName = "${DOCKER_REGISTRY}/observability-ci/${name}${variant}:${tagName}" | ||
def commitName = "${DOCKER_REGISTRY}/observability-ci/${name}${variant}:${env.GIT_BASE_COMMIT}" | ||
doTagAndPush(beatName, variant, libbetaVer, tagName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm moving the generation of the docker image name to the method, hiding the implementation |
||
doTagAndPush(beatName, variant, libbetaVer, "${env.GIT_BASE_COMMIT}") | ||
|
||
def iterations = 0 | ||
retryWithSleep(retries: 3, seconds: 5, backoff: true) { | ||
iterations++ | ||
def status = sh(label:'Change tag and push', script: """ | ||
docker tag ${oldName} ${newName} | ||
docker push ${newName} | ||
docker tag ${oldName} ${commitName} | ||
docker push ${commitName} | ||
""", returnStatus: true) | ||
if (!isPR() && aliasVersion != "") { | ||
doTagAndPush(beatName, variant, libbetaVer, aliasVersion) | ||
} | ||
} | ||
} | ||
|
||
if ( status > 0 && iterations < 3) { | ||
error('tag and push failed, retry') | ||
} else if ( status > 0 ) { | ||
log(level: 'WARN', text: "${name} doesn't have ${variant} docker images. See https://github.com/elastic/beats/pull/21621") | ||
} | ||
/** | ||
* @param beatName name of the Beat | ||
* @param variant name of the variant used to build the docker image name | ||
* @param sourceTag tag to be used as source for the docker tag command, usually under the 'beats' namespace | ||
* @param targetTag tag to be used as target for the docker tag command, usually under the 'observability-ci' namespace | ||
*/ | ||
def doTagAndPush(beatName, variant, sourceTag, targetTag) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @v1v for the suggestion! this refactor extracting the common logic to a method helps with potential debug if/when tag/push fails, as each retagged image is decoupled. |
||
def sourceName = "${DOCKER_REGISTRY}/beats/${beatName}${variant}:${sourceTag}" | ||
def targetName = "${DOCKER_REGISTRY}/observability-ci/${beatName}${variant}:${targetTag}" | ||
|
||
def iterations = 0 | ||
retryWithSleep(retries: 3, seconds: 5, backoff: true) { | ||
iterations++ | ||
def status = sh(label: "Change tag and push ${targetName}", script: """ | ||
docker tag ${sourceName} ${targetName} | ||
docker push ${targetName} | ||
""", returnStatus: true) | ||
|
||
if ( status > 0 && iterations < 3) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all beats has OSS and UBI8 variant? IIRC not all have OSS, so it will throw 3 errors on those cases, it is a little weird fail by default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are logging the message on errors. We could build a data structure with the combinations, but we thought that this was simpler |
||
error("tag and push failed for ${beatName}, retry") | ||
} else if ( status > 0 ) { | ||
log(level: 'WARN', text: "${beatName} doesn't have ${variant} docker images. See https://github.com/elastic/beats/pull/21621") | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rename of this variable is a cosmetic change for readability sake