Skip to content
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

ci: transform git tag with v format #865

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}