Skip to content

Commit

Permalink
Fixed wrong behaivor on registries with non default ports
Browse files Browse the repository at this point in the history
- 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 <markush1986@gmail.com>
  • Loading branch information
aidun committed May 2, 2020
1 parent b0a70a3 commit f50137f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 12 additions & 1 deletion schema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
18 changes: 18 additions & 0 deletions schema/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ 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)
}
}

func Test_BuildImageName_RegistryWithPortAndTag(t *testing.T) {
want := "registry.domain:8080/image:foo"
got := BuildImageName(DefaultFormat, "registry.domain:8080/image:foo", "ef384", "master")

if got != want {
t.Errorf("BuildImageName want: \"%s\", got: \"%s\"", want, got)
}
}

0 comments on commit f50137f

Please sign in to comment.