diff --git a/core/common.go b/core/common.go index 701b38ac..9f4de878 100644 --- a/core/common.go +++ b/core/common.go @@ -240,27 +240,34 @@ func buildFindLocalImageOptions(image string) docker.ListImagesOptions { } func buildPullOptions(image string) (docker.PullImageOptions, docker.AuthConfiguration) { - tag := "latest" - registry := "" + repository, tag := docker.ParseRepositoryTag(image) - parts := strings.Split(image, ":") - if len(parts) == 2 { - tag = parts[1] - } + registry := parseRegistry(repository) - name := parts[0] - parts = strings.Split(name, "/") - if len(parts) > 2 { - registry = parts[0] + if tag == "" { + tag = "latest" } return docker.PullImageOptions{ - Repository: name, + Repository: repository, Registry: registry, - Tag: tag, + Tag: tag, }, buildAuthConfiguration(registry) } +func parseRegistry(repository string) string { + parts := strings.Split(repository, "/") + if len(parts) < 2 { + return "" + } + + if strings.ContainsAny(parts[0], ".:") || len(parts) > 2 { + return parts[0] + } + + return "" +} + func buildAuthConfiguration(registry string) docker.AuthConfiguration { var auth docker.AuthConfiguration if dockercfg == nil { diff --git a/core/common_test.go b/core/common_test.go index dc0cae55..d7430e5b 100644 --- a/core/common_test.go +++ b/core/common_test.go @@ -316,3 +316,10 @@ func (*TestLogger) Debugf(format string, args ...interface{}) {} func (*TestLogger) Errorf(format string, args ...interface{}) {} func (*TestLogger) Noticef(format string, args ...interface{}) {} func (*TestLogger) Warningf(format string, args ...interface{}) {} + +func (s *SuiteCommon) TestParseRegistry(c *C) { + c.Assert(parseRegistry("example.com:port/dir/image"), Equals, "example.com:port") + c.Assert(parseRegistry("example.com:port/image"), Equals, "example.com:port") + c.Assert(parseRegistry("dir/image"), Equals, "") + c.Assert(parseRegistry("image"), Equals, "") +}