diff --git a/schema/image.go b/schema/image.go index 4fd3b018d..5cfb0ab23 100644 --- a/schema/image.go +++ b/schema/image.go @@ -65,7 +65,18 @@ func (i *BuildFormat) Set(value string) error { // BuildImageName builds a Docker image tag for build, push or deploy func BuildImageName(format BuildFormat, image string, version string, branch string) string { imageVal := image - if strings.Contains(image, ":") == false { + + colon_count := strings.Count(image, ":") + if colon_count > 0 { + + slash_index := strings.Index(image, "/") + colon_index := strings.Index(image, ":") + + if slash_index-colon_index > 0 && colon_count == 1 { + imageVal += ":latest" + } + + } else { imageVal += ":latest" } diff --git a/schema/image_test.go b/schema/image_test.go index e3c3ebd39..6bb6f485c 100644 --- a/schema/image_test.go +++ b/schema/image_test.go @@ -37,3 +37,12 @@ func Test_BuildImageName_BranchAndSHAFormat(t *testing.T) { t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got) } } + +func Test_BuildImageName_RegistryWithPort(t *testing.T) { + want := "registry.domain:8080/image:latest" + got := BuildImageName(DefaultFormat, "registry.domain:8080/image", "ef384", "master") + + if got != want { + t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got) + } +}