Skip to content

Commit

Permalink
Always include tag in tarball refs (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr authored Jan 13, 2021
1 parent 0d81a61 commit 4eb508c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 15 additions & 4 deletions pkg/v1/tarball/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,22 @@ func dedupRefToImage(refToImage map[name.Reference]v1.Image) map[v1.Image][]stri

for ref, img := range refToImage {
if tag, ok := ref.(name.Tag); ok {
if tags, ok := imageToTags[img]; ok && tags != nil {
imageToTags[img] = append(tags, tag.String())
} else {
imageToTags[img] = []string{tag.String()}
if tags, ok := imageToTags[img]; !ok || tags == nil {
imageToTags[img] = []string{}
}
// Docker cannot load tarballs without an explicit tag:
// https://github.com/google/go-containerregistry/issues/890
//
// We can't use the fully qualified tag.Name() because of rules_docker:
// https://github.com/google/go-containerregistry/issues/527
//
// If the tag is "latest", but tag.String() doesn't end in ":latest",
// just append it. Kind of gross, but should work for now.
ts := tag.String()
if tag.Identifier() == name.DefaultTag && !strings.HasSuffix(ts, ":"+name.DefaultTag) {
ts = fmt.Sprintf("%s:%s", ts, name.DefaultTag)
}
imageToTags[img] = append(imageToTags[img], ts)
} else {
if _, ok := imageToTags[img]; !ok {
imageToTags[img] = nil
Expand Down
10 changes: 7 additions & 3 deletions pkg/v1/tarball/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ func TestWriteSharedLayers(t *testing.T) {
}

func TestComputeManifest(t *testing.T) {
var randomTag, mutatedTag = "gcr.io/foo/bar:latest", "gcr.io/baz/bat:latest"
var randomTag, mutatedTag = "ubuntu", "gcr.io/baz/bat:latest"

// https://github.com/google/go-containerregistry/issues/890
randomTagWritten := "ubuntu:latest"

// Make a random image
randImage, err := random.Image(256, 1)
if err != nil {
Expand All @@ -388,7 +392,7 @@ func TestComputeManifest(t *testing.T) {
if err != nil {
t.Fatalf("error getting random image config: %v", err)
}
tag1, err := name.NewTag(randomTag, name.StrictValidation)
tag1, err := name.NewTag(randomTag)
if err != nil {
t.Fatalf("Error creating test tag1.")
}
Expand Down Expand Up @@ -441,7 +445,7 @@ func TestComputeManifest(t *testing.T) {
},
{
Config: randConfig.String(),
RepoTags: []string{randomTag},
RepoTags: []string{randomTagWritten},
Layers: randomLayersFilenames,
},
}
Expand Down

0 comments on commit 4eb508c

Please sign in to comment.