summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2018-07-28 04:05:31 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-01 18:22:59 +0000
commita5c1cecbeaebf44401b9c666d9d544f4d5aafdb4 (patch)
treefb20512996add7c1bd7007ae64c689b6b59b4be7 /cmd/podman
parent754fc8e8ecf98ebd34140ee1414f96665d84b883 (diff)
downloadpodman-a5c1cecbeaebf44401b9c666d9d544f4d5aafdb4.tar.gz
podman-a5c1cecbeaebf44401b9c666d9d544f4d5aafdb4.tar.bz2
podman-a5c1cecbeaebf44401b9c666d9d544f4d5aafdb4.zip
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
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/save.go31
1 files 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)
}