Strip v prefix in git tag name when publishing in Docker.

This commit is contained in:
Clement Michaud 2019-12-10 09:21:54 +01:00
parent d4e236bc66
commit bd2ddc5e90

View File

@ -19,7 +19,7 @@ var defaultArch = "amd64"
var travisBranch = os.Getenv("TRAVIS_BRANCH") var travisBranch = os.Getenv("TRAVIS_BRANCH")
var travisPullRequest = os.Getenv("TRAVIS_PULL_REQUEST") var travisPullRequest = os.Getenv("TRAVIS_PULL_REQUEST")
var travisTag = os.Getenv("TRAVIS_TAG") var travisTag = os.Getenv("TRAVIS_TAG")
var dockerTags = regexp.MustCompile(`(?P<Minor>(?P<Major>v\d+)\.\d+)\.\d+.*`) var dockerTags = regexp.MustCompile(`v(?P<Patch>(?P<Minor>(?P<Major>\d+)\.\d+)\.\d+.*)`)
var ignoredSuffixes = regexp.MustCompile("alpha|beta") var ignoredSuffixes = regexp.MustCompile("alpha|beta")
var tags = dockerTags.FindStringSubmatch(travisTag) var tags = dockerTags.FindStringSubmatch(travisTag)
@ -204,17 +204,19 @@ func publishDockerImage(arch string) {
login(docker) login(docker)
deploy(docker, "master-"+arch) deploy(docker, "master-"+arch)
} else if travisTag != "" { } else if travisTag != "" {
if len(tags) == 3 { if len(tags) == 4 {
fmt.Printf("Detected tags: '%s' | '%s' | '%s'", tags[1], tags[2], tags[3])
login(docker) login(docker)
deploy(docker, tags[0]+"-"+arch) deploy(docker, tags[1]+"-"+arch)
if !ignoredSuffixes.MatchString(travisTag) {
deploy(docker, tags[2]+"-"+arch)
deploy(docker, tags[3]+"-"+arch)
deploy(docker, "latest-"+arch)
}
} else { } else {
log.Fatal("Docker image will not be published, the specified tag does not conform to the standard") log.Fatal("Docker image will not be published, the specified tag does not conform to the standard")
} }
if !ignoredSuffixes.MatchString(travisTag) {
deploy(docker, tags[1]+"-"+arch)
deploy(docker, tags[2]+"-"+arch)
deploy(docker, "latest-"+arch)
}
} else { } else {
log.Info("Docker image will not be published") log.Info("Docker image will not be published")
} }
@ -227,17 +229,20 @@ func publishDockerManifest() {
login(docker) login(docker)
deployManifest(docker, "master", "master-amd64", "master-arm32v7", "master-arm64v8") deployManifest(docker, "master", "master-amd64", "master-arm32v7", "master-arm64v8")
} else if travisTag != "" { } else if travisTag != "" {
if len(tags) == 3 { if len(tags) == 4 {
fmt.Printf("Detected tags: '%s' | '%s' | '%s'", tags[1], tags[2], tags[3])
login(docker) login(docker)
deployManifest(docker, tags[0], tags[0]+"-amd64", tags[0]+"-arm32v7", tags[0]+"-arm64v8") deployManifest(docker, tags[1], tags[1]+"-amd64", tags[1]+"-arm32v7", tags[1]+"-arm64v8")
if !ignoredSuffixes.MatchString(travisTag) {
deployManifest(docker, tags[2], tags[2]+"-amd64", tags[2]+"-arm32v7", tags[2]+"-arm64v8")
deployManifest(docker, tags[3], tags[3]+"-amd64", tags[3]+"-arm32v7", tags[3]+"-arm64v8")
deployManifest(docker, "latest", "latest-amd64", "latest-arm32v7", "latest-arm64v8")
}
} else { } else {
log.Fatal("Docker manifest will not be published, the specified tag does not conform to the standard") log.Fatal("Docker manifest will not be published, the specified tag does not conform to the standard")
} }
if !ignoredSuffixes.MatchString(travisTag) {
deployManifest(docker, tags[1], tags[1]+"-amd64", tags[1]+"-arm32v7", tags[1]+"-arm64v8")
deployManifest(docker, tags[2], tags[2]+"-amd64", tags[2]+"-arm32v7", tags[2]+"-arm64v8")
deployManifest(docker, "latest", "latest-amd64", "latest-arm32v7", "latest-arm64v8")
}
} else { } else {
fmt.Println("Docker manifest will not be published") fmt.Println("Docker manifest will not be published")
} }