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

Fixes podman save fails when specifying an image using a digest fixes-5234 #6011

Merged
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
27 changes: 22 additions & 5 deletions libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1487,14 +1487,14 @@ func (i *Image) Save(ctx context.Context, source, format, output string, moreTag
}
manifestType = manifest.DockerV2Schema2MediaType
case "docker-archive", "":
dst := output
destImageName := imageNameForSaveDestination(i, source)
if destImageName != "" {
dst = fmt.Sprintf("%s:%s", dst, destImageName)
ref, err := dockerArchiveDstReference(destImageName)
if err != nil {
return err
}
destRef, err = dockerarchive.ParseReference(dst) // FIXME? Add dockerarchive.NewReference
destRef, err = dockerarchive.NewReference(output, ref)
if err != nil {
return errors.Wrapf(err, "error getting Docker archive ImageReference for %q", dst)
return errors.Wrapf(err, "error getting Docker archive ImageReference for %s:%v", output, ref)
}
default:
return errors.Errorf("unknown format option %q", format)
Expand All @@ -1514,6 +1514,23 @@ func (i *Image) Save(ctx context.Context, source, format, output string, moreTag
return nil
}

// dockerArchiveDestReference returns a NamedTagged reference for a tagged image and nil for untagged image.
func dockerArchiveDstReference(normalizedInput string) (reference.NamedTagged, error) {
if normalizedInput == "" {
return nil, nil
}
ref, err := reference.ParseNormalizedNamed(normalizedInput)
if err != nil {
return nil, errors.Wrapf(err, "docker-archive parsing reference %s", normalizedInput)
}
ref = reference.TagNameOnly(ref)
namedTagged, isTagged := ref.(reference.NamedTagged)
if !isTagged {
namedTagged = nil
}
return namedTagged, nil
}

// GetConfigBlob returns a schema2image. If the image is not a schema2, then
// it will return an error
func (i *Image) GetConfigBlob(ctx context.Context) (*manifest.Schema2Image, error) {
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,16 @@ var _ = Describe("Podman save", func() {
Expect(save).To(ExitWithError())
})

It("podman save image with digest reference", func() {
// pull a digest reference
session := podmanTest.PodmanNoCache([]string{"pull", ALPINELISTDIGEST})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

// save a digest reference should exit without error.
outfile := filepath.Join(podmanTest.TempDir, "temp.tar")
save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, ALPINELISTDIGEST})
save.WaitWithDefaultTimeout()
Expect(save.ExitCode()).To(Equal(0))
})
})