mirror of
https://github.com/containers/podman.git
synced 2025-06-28 22:53:21 +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"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/image/directory"
|
||||||
|
dockerarchive "github.com/containers/image/docker/archive"
|
||||||
"github.com/containers/image/docker/reference"
|
"github.com/containers/image/docker/reference"
|
||||||
"github.com/containers/image/manifest"
|
"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"
|
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||||
@ -99,28 +103,39 @@ func saveCmd(c *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var dst, manifestType string
|
var destRef types.ImageReference
|
||||||
|
var manifestType string
|
||||||
switch c.String("format") {
|
switch c.String("format") {
|
||||||
case libpod.OCIArchive:
|
case libpod.OCIArchive:
|
||||||
dst = libpod.OCIArchive + ":" + output
|
|
||||||
destImageName := imageNameForSaveDestination(newImage, source)
|
destImageName := imageNameForSaveDestination(newImage, source)
|
||||||
if destImageName != "" {
|
destRef, err = ociarchive.NewReference(output, destImageName) // destImageName may be ""
|
||||||
dst = fmt.Sprintf("%s:%s", dst, destImageName)
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "error getting OCI archive ImageReference for (%q, %q)", output, destImageName)
|
||||||
}
|
}
|
||||||
case "oci-dir":
|
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
|
manifestType = imgspecv1.MediaTypeImageManifest
|
||||||
case "docker-dir":
|
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
|
manifestType = manifest.DockerV2Schema2MediaType
|
||||||
case libpod.DockerArchive:
|
case libpod.DockerArchive:
|
||||||
fallthrough
|
fallthrough
|
||||||
case "":
|
case "":
|
||||||
dst = libpod.DockerArchive + ":" + output
|
dst := output
|
||||||
destImageName := imageNameForSaveDestination(newImage, source)
|
destImageName := imageNameForSaveDestination(newImage, source)
|
||||||
if destImageName != "" {
|
if destImageName != "" {
|
||||||
dst = fmt.Sprintf("%s:%s", dst, 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:
|
default:
|
||||||
return errors.Errorf("unknown format option %q", c.String("format"))
|
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 {
|
if err2 := os.Remove(output); err2 != nil {
|
||||||
logrus.Errorf("error deleting %q: %v", output, err)
|
logrus.Errorf("error deleting %q: %v", output, err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user