mirror of
https://github.com/containers/podman.git
synced 2025-06-26 21:07:02 +08:00
Use PushImageToReference for (podman save)
To do that, create the relevant ImageReference values directly by calling ParseReference/NewReference from the relevant transport subpackages instead of formatting strings to be parsed (and heuristically re-parsed) by PushImage. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Closes: #1176 Approved by: rhatdan
This commit is contained in:

committed by
Atomic Bot

parent
754fc8e8ec
commit
a5c1cecbea
@ -6,8 +6,12 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/image/directory"
|
||||
dockerarchive "github.com/containers/image/docker/archive"
|
||||
"github.com/containers/image/docker/reference"
|
||||
"github.com/containers/image/manifest"
|
||||
ociarchive "github.com/containers/image/oci/archive"
|
||||
"github.com/containers/image/types"
|
||||
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||
@ -99,28 +103,39 @@ func saveCmd(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var dst, manifestType string
|
||||
var destRef types.ImageReference
|
||||
var manifestType string
|
||||
switch c.String("format") {
|
||||
case libpod.OCIArchive:
|
||||
dst = libpod.OCIArchive + ":" + output
|
||||
destImageName := imageNameForSaveDestination(newImage, source)
|
||||
if destImageName != "" {
|
||||
dst = fmt.Sprintf("%s:%s", dst, destImageName)
|
||||
destRef, err = ociarchive.NewReference(output, destImageName) // destImageName may be ""
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error getting OCI archive ImageReference for (%q, %q)", output, destImageName)
|
||||
}
|
||||
case "oci-dir":
|
||||
dst = libpod.DirTransport + ":" + output
|
||||
destRef, err = directory.NewReference(output)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error getting directory ImageReference for %q", output)
|
||||
}
|
||||
manifestType = imgspecv1.MediaTypeImageManifest
|
||||
case "docker-dir":
|
||||
dst = libpod.DirTransport + ":" + output
|
||||
destRef, err = directory.NewReference(output)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error getting directory ImageReference for %q", output)
|
||||
}
|
||||
manifestType = manifest.DockerV2Schema2MediaType
|
||||
case libpod.DockerArchive:
|
||||
fallthrough
|
||||
case "":
|
||||
dst = libpod.DockerArchive + ":" + output
|
||||
dst := output
|
||||
destImageName := imageNameForSaveDestination(newImage, source)
|
||||
if destImageName != "" {
|
||||
dst = fmt.Sprintf("%s:%s", dst, destImageName)
|
||||
}
|
||||
destRef, err = dockerarchive.ParseReference(dst) // FIXME? Add dockerarchive.NewReference
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error getting Docker archive ImageReference for %q", dst)
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unknown format option %q", c.String("format"))
|
||||
}
|
||||
@ -134,7 +149,7 @@ func saveCmd(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := newImage.PushImage(getContext(), dst, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false, additionaltags); err != nil {
|
||||
if err := newImage.PushImageToReference(getContext(), destRef, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false, additionaltags); err != nil {
|
||||
if err2 := os.Remove(output); err2 != nil {
|
||||
logrus.Errorf("error deleting %q: %v", output, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user