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 <[email protected]>
  • Loading branch information
aidun committed Mar 22, 2020
1 parent b0a70a3 commit 3adf24a
Show file tree
Hide file tree
Showing 2 changed files with 21 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
9 changes: 9 additions & 0 deletions schema/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 3adf24a

Please sign in to comment.