Set dynamic branch name for Docker image tags in build.gradle (#7780)

release-2.21 v2.21.9
John Niang 2025-09-24 12:17:33 +08:00 committed by GitHub
parent 50405a9409
commit db00883c3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -198,11 +198,12 @@ tasks.named('generateOpenApiDocs') {
}
def name = 'halo'
def branchName = grgit.branch.current().name.replaceAll("/", "-")
def tagName = "${project.version}-cnb"
def isRelease = Objects.equals(project.findProperty('release'), 'true')
if (!isRelease) {
name = 'halo-dev'
tagName = "cnb-sha-${grgit.head().abbreviatedId}"
tagName = "sha-${grgit.head().abbreviatedId}-cnb"
}
tasks.register('publishToGhcr', BootBuildImage) {
@ -211,7 +212,7 @@ tasks.register('publishToGhcr', BootBuildImage) {
imageName = "ghcr.io/halo-dev/${name}:${tagName}"
publish = StringUtils.hasText(System.getenv('GHCR_TOKEN'))
if (!isRelease) {
tags = ["ghcr.io/halo-dev/${name}:cnb-main".toString()]
tags = ["ghcr.io/halo-dev/${name}:${branchName}-cnb".toString()]
}
docker {
publishRegistry {
@ -228,7 +229,7 @@ tasks.register('publishToDockerHub', BootBuildImage) {
imageName = "halohub/${name}:${tagName}"
publish = StringUtils.hasText(System.getenv('DOCKER_TOKEN'))
if (!isRelease) {
tags = ["halohub/${name}:cnb-main".toString()]
tags = ["halohub/${name}:${branchName}-cnb".toString()]
}
docker {
publishRegistry {