Skip to content

Commit f50137f

Browse files
committed
Fixed wrong behaivor on registries with non default ports
- Added unit test which covers imagename creation with registries on non default ports. - Added fix for BuildImageName on registries on non default ports Signed-off-by: Markus Hartmann <[email protected]>
1 parent b0a70a3 commit f50137f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

schema/image.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ func (i *BuildFormat) Set(value string) error {
6565
// BuildImageName builds a Docker image tag for build, push or deploy
6666
func BuildImageName(format BuildFormat, image string, version string, branch string) string {
6767
imageVal := image
68-
if strings.Contains(image, ":") == false {
68+
69+
colon_count := strings.Count(image, ":")
70+
if colon_count > 0 {
71+
72+
slash_index := strings.Index(image, "/")
73+
colon_index := strings.Index(image, ":")
74+
75+
if slash_index-colon_index > 0 && colon_count == 1 {
76+
imageVal += ":latest"
77+
}
78+
79+
} else {
6980
imageVal += ":latest"
7081
}
7182

schema/image_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,21 @@ func Test_BuildImageName_BranchAndSHAFormat(t *testing.T) {
3737
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
3838
}
3939
}
40+
41+
func Test_BuildImageName_RegistryWithPort(t *testing.T) {
42+
want := "registry.domain:8080/image:latest"
43+
got := BuildImageName(DefaultFormat, "registry.domain:8080/image", "ef384", "master")
44+
45+
if got != want {
46+
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
47+
}
48+
}
49+
50+
func Test_BuildImageName_RegistryWithPortAndTag(t *testing.T) {
51+
want := "registry.domain:8080/image:foo"
52+
got := BuildImageName(DefaultFormat, "registry.domain:8080/image:foo", "ef384", "master")
53+
54+
if got != want {
55+
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
56+
}
57+
}

0 commit comments

Comments
 (0)