Skip to content

Commit

Permalink
fix manifest tag index in manifest.go (#731)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Aronsson <[email protected]>
  • Loading branch information
piksel and simskij authored Jan 2, 2021
1 parent 2fb1f5f commit 3bbe1bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/registry/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
Expand Down
9 changes: 9 additions & 0 deletions pkg/registry/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

})

0 comments on commit 3bbe1bd

Please sign in to comment.