Skip to content

Commit

Permalink
ci: transform git tag with v format (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Aug 18, 2022
1 parent 916a57e commit 3a32ddf
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions .ci/release-package-registry-distribution.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ pipeline {
DOCKER_REGISTRY = 'docker.elastic.co'
DOCKER_REGISTRY_SECRET = 'secret/observability-team/ci/docker-registry/prod'
DOCKER_TAG = "${params.DOCKER_TAG}"
DOCKER_IMG_SOURCE = "${env.DOCKER_REGISTRY}/package-registry/distribution:production"
DOCKER_IMG_TARGET = "${env.DOCKER_REGISTRY}/package-registry/distribution:${env.DOCKER_TAG}"
}
options {
timeout(time: 1, unit: 'HOURS')
Expand All @@ -30,17 +28,15 @@ pipeline {
stage('Validate docker tag'){
options { skipDefaultCheckout() }
steps {
// Validate only semver are allowed for the docker tag.
// It's allowed to override existing published docker images. For instance, the build candidates generated
// by the unified release process will share the same versioning, therefore the Git release tag will be
// the last docker image to be republished.
whenFalse(isSemVerValid(env.DOCKER_TAG)) {
error('unsupported docker tag, please use the major.minor.path(-prerelease)? format (for example: 1.2.3 or 1.2.3-alpha).')
}
transformTagAndValidate()
}
}
stage('Publish Docker image'){
options { skipDefaultCheckout() }
environment {
DOCKER_IMG_SOURCE = "${env.DOCKER_REGISTRY}/package-registry/distribution:production"
DOCKER_IMG_TARGET = "${env.DOCKER_REGISTRY}/package-registry/distribution:${env.DOCKER_TAG_VERSION}"
}
steps {
dockerLogin(secret: "${env.DOCKER_REGISTRY_SECRET}", registry: "${env.DOCKER_REGISTRY}")
retryWithSleep(retries: 3, seconds: 5, backoff: true) {
Expand All @@ -64,3 +60,22 @@ def isSemVerValid(String version) {
def match = version =~ /\d+.\d+.\d+(-\w+)?/
return match.matches()
}

/**
* Transform the DOCKER_TAG to be a valid docker tag format in case
* it contains the git tag with the 'v' prefix
*/
def transformTagAndValidate() {
// If the docker tag contains the 'v' prefix, then remove it.
// fleet-server and other projects use tag releases with v<major>.<minor>.<patch>
// i.e: v8.3.1
def version = env.DOCKER_TAG.replaceAll('^v', '')
// Validate only semver are allowed for the docker tag.
// It's allowed to override existing published docker images. For instance, the build candidates generated
// by the unified release process will share the same versioning, therefore the Git release tag will be
// the last docker image to be republished.
if (!isSemVerValid(version)) {
error('unsupported docker tag, please use the major.minor.path(-prerelease)? format (for example: 1.2.3 or 1.2.3-alpha).')
}
env.DOCKER_TAG_VERSION = version
}

0 comments on commit 3a32ddf

Please sign in to comment.