diff --git a/pkg/v1/tarball/write.go b/pkg/v1/tarball/write.go index cceb16cd3..1a5eee7f6 100644 --- a/pkg/v1/tarball/write.go +++ b/pkg/v1/tarball/write.go @@ -334,11 +334,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 diff --git a/pkg/v1/tarball/write_test.go b/pkg/v1/tarball/write_test.go index 8552950b3..57e91def2 100644 --- a/pkg/v1/tarball/write_test.go +++ b/pkg/v1/tarball/write_test.go @@ -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 { @@ -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.") } @@ -441,7 +445,7 @@ func TestComputeManifest(t *testing.T) { }, { Config: randConfig.String(), - RepoTags: []string{randomTag}, + RepoTags: []string{randomTagWritten}, Layers: randomLayersFilenames, }, }