From a5c1cecbeaebf44401b9c666d9d544f4d5aafdb4 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 28 Jul 2018 04:05:31 +0200 Subject: Use PushImageToReference for (podman save) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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č Closes: #1176 Approved by: rhatdan --- cmd/podman/save.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/podman/save.go b/cmd/podman/save.go index bc5f816e8..a60403b64 100644 --- a/cmd/podman/save.go +++ b/cmd/podman/save.go @@ -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) } -- cgit v1.2.3-54-g00ecf