Skip to content

Commit

Permalink
Correctly extract image name when using custom hub.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwilkie committed Jan 15, 2016
1 parent d3ffd85 commit 3488087
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions render/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,14 @@ func MapPod2Service(n RenderableNode, _ report.Networks) RenderableNodes {
return result
}

var dockerImageMatch = regexp.MustCompile(`(?:(?P<reg>[^/]+)/)?(?P<name>[^/]+/[^:]+):(?P<version>.*)`)

func imageNameWithoutVersion(name string) string {
parts := strings.SplitN(name, ":", 2)
if len(parts) == 2 {
return parts[0]
mapping := dockerImageMatch.FindStringSubmatch(name)
if mapping == nil {
return name
}
return name
return mapping[2]
}

// MapContainerImage2Name maps container images RenderableNodes to
Expand Down
23 changes: 23 additions & 0 deletions render/mapping_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package render

import (
"testing"
)

func TestDockerImageRegexp(t *testing.T) {
for _, input := range []struct{ in, reg, image, ver string }{
{"foo/bar:baz", "", "foo/bar", "baz"},
{"reg:123/foo/bar:baz", "reg:123", "foo/bar", "baz"},
{"docker-registry.domain.name:5000/repo/image1:ver", "docker-registry.domain.name:5000", "repo/image1", "ver"},
} {
mapping := dockerImageMatch.FindStringSubmatch(input.in)
if mapping == nil {
t.Fatalf("No match: %v", input)
}
if mapping[1] != input.reg ||
mapping[2] != input.image ||
mapping[3] != input.ver {
t.Fatalf("Bad regexp: %v, %v", mapping, input)
}
}
}

0 comments on commit 3488087

Please sign in to comment.