Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always include tag in tarball refs #893

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/v1/tarball/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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