From 3cd405d090ba9fa80ba5a2cc1d79922875ff6ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Mon, 19 Oct 2020 12:51:40 +0200 Subject: [PATCH] feat: push aliases for docker images --- .ci/packaging.groovy | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.ci/packaging.groovy b/.ci/packaging.groovy index 4145ee6bdd1..1f4865d7e98 100644 --- a/.ci/packaging.groovy +++ b/.ci/packaging.groovy @@ -193,8 +193,12 @@ def pushCIDockerImages(){ def tagAndPush(name){ 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}" @@ -227,6 +231,24 @@ def tagAndPush(name){ log(level: 'WARN', text: "${name} doesn't have ${variant} docker images. See https://github.com/elastic/beats/pull/21621") } } + + if (aliasVersion != "") { + def aliasName = "${DOCKER_REGISTRY}/observability-ci/${name}${variant}:${aliasVersion}" + def iterations = 0 + retryWithSleep(retries: 3, seconds: 5, backoff: true) { + iterations++ + def status = sh(label:'Change tag and push', script: """ + docker tag ${oldName} ${aliasName} + docker push ${newName} + """, returnStatus: true) + + 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") + } + } + } } }