diff --git a/pkg/registry/manifest/manifest.go b/pkg/registry/manifest/manifest.go index aac7762..facbb6c 100644 --- a/pkg/registry/manifest/manifest.go +++ b/pkg/registry/manifest/manifest.go @@ -20,7 +20,7 @@ func BuildManifestURL(container types.Container) (string, error) { } host, err := helpers.NormalizeRegistry(normalizedName.String()) - img, tag := extractImageAndTag(strings.TrimPrefix(container.ImageName(), host+"/")) + img, tag := ExtractImageAndTag(strings.TrimPrefix(container.ImageName(), host+"/")) logrus.WithFields(logrus.Fields{ "image": img, @@ -45,15 +45,16 @@ func BuildManifestURL(container types.Container) (string, error) { return url.String(), nil } -func extractImageAndTag(imageName string) (string, string) { +// ExtractImageAndTag from a concatenated string +func ExtractImageAndTag(imageName string) (string, string) { var img string var tag string if strings.Contains(imageName, ":") { parts := strings.Split(imageName, ":") if len(parts) > 2 { - img = fmt.Sprintf("%s%s", parts[0], parts[1]) - tag = parts[3] + img = parts[0] + tag = strings.Join(parts[1:], ":") } else { img = parts[0] tag = parts[1] diff --git a/pkg/registry/manifest/manifest_test.go b/pkg/registry/manifest/manifest_test.go index 3b86f90..95f196b 100644 --- a/pkg/registry/manifest/manifest_test.go +++ b/pkg/registry/manifest/manifest_test.go @@ -61,6 +61,15 @@ var _ = Describe("the manifest module", func() { Expect(err).NotTo(HaveOccurred()) Expect(res).To(Equal(expected)) }) + It("should combine the tag name and digest pinning into one digest, given multiple colons", func() { + in := "containrrr/watchtower:latest@sha256:daf7034c5c89775afe3008393ae033529913548243b84926931d7c84398ecda7" + image, tag := "containrrr/watchtower", "latest@sha256:daf7034c5c89775afe3008393ae033529913548243b84926931d7c84398ecda7" + + imageOut, tagOut := manifest.ExtractImageAndTag(in) + + Expect(imageOut).To(Equal(image)) + Expect(tagOut).To(Equal(tag)) + }) }) })