Initial support for tagging with git desribe output

**What**
- Adds new GetGitDescribe ouput command, use this command in the build,
deploy, generate, and push commands.

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This commit is contained in:
Lucas Roesler
2019-09-01 13:06:01 +02:00
committed by Alex Ellis
parent 860b769167
commit 027157327f
7 changed files with 97 additions and 90 deletions

View File

@@ -9,23 +9,32 @@ type BuildFormat int
// DefaultFormat as defined in the YAML file or appending :latest
const DefaultFormat BuildFormat = 0
// SHAFormat uses "latest-<sha>" as the docker tag
const SHAFormat BuildFormat = 1
// BranchAndSHAFormat uses "latest-<branch>-<sha>" as the docker tag
const BranchAndSHAFormat BuildFormat = 2
// DescribeFormat uses the git-describe output as the docker tag
const DescribeFormat BuildFormat = 3
// BuildImageName builds a Docker image tag for build, push or deploy
func BuildImageName(format BuildFormat, image string, SHA string, branch string) string {
func BuildImageName(format BuildFormat, image string, version string, branch string) string {
imageVal := image
if strings.Contains(image, ":") == false {
imageVal += ":latest"
}
if format == SHAFormat {
return imageVal + "-" + SHA
switch format {
case SHAFormat:
return imageVal + "-" + version
case BranchAndSHAFormat:
return imageVal + "-" + branch + "-" + version
case DescribeFormat:
// should we trim the existing image tag and do a proper replace with
// the describe describe value
return imageVal + "-" + version
default:
return imageVal
}
if format == BranchAndSHAFormat {
return imageVal + "-" + branch + "-" + SHA
}
return imageVal
}