summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/commands.go2
-rw-r--r--cmd/podman/image.go1
-rw-r--r--cmd/podman/main.go1
-rw-r--r--cmd/podman/save.go106
-rw-r--r--cmd/podman/varlink/io.podman.varlink12
5 files changed, 18 insertions, 104 deletions
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go
index 27ac342ba..387e35767 100644
--- a/cmd/podman/commands.go
+++ b/cmd/podman/commands.go
@@ -30,7 +30,6 @@ func getMainCommands() []*cobra.Command {
_restoreCommand,
_rmCommand,
_runCommand,
- _saveCommand,
_searchCommand,
_signCommand,
_startCommand,
@@ -53,7 +52,6 @@ func getMainCommands() []*cobra.Command {
func getImageSubCommands() []*cobra.Command {
return []*cobra.Command{
_loadCommand,
- _saveCommand,
_signCommand,
}
}
diff --git a/cmd/podman/image.go b/cmd/podman/image.go
index 4f9c7cd6a..3c8942ef5 100644
--- a/cmd/podman/image.go
+++ b/cmd/podman/image.go
@@ -28,6 +28,7 @@ var imageSubCommands = []*cobra.Command{
_pullCommand,
_pushCommand,
_rmiCommand,
+ _saveCommand,
_tagCommand,
}
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index ecb72f58b..5fa6cf233 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -48,6 +48,7 @@ var mainCommands = []*cobra.Command{
_pullCommand,
_pushCommand,
_rmiCommand,
+ _saveCommand,
_tagCommand,
_versionCommand,
imageCommand.Command,
diff --git a/cmd/podman/save.go b/cmd/podman/save.go
index ff4a22453..ba5209f34 100644
--- a/cmd/podman/save.go
+++ b/cmd/podman/save.go
@@ -1,21 +1,10 @@
package main
import (
- "fmt"
- "io"
"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"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
- libpodImage "github.com/containers/libpod/libpod/image"
- imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
+ "github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -52,7 +41,7 @@ func init() {
saveCommand.SetUsageTemplate(UsageTemplate())
flags := saveCommand.Flags()
flags.BoolVar(&saveCommand.Compress, "compress", false, "Compress tarball image layers when saving to a directory using the 'dir' transport. (default is same compression type as source)")
- flags.StringVar(&saveCommand.Format, "format", "", "Save image to oci-archive, oci-dir (directory with oci manifest type), docker-dir (directory with v2s2 manifest type)")
+ flags.StringVar(&saveCommand.Format, "format", "docker-archive", "Save image to oci-archive, oci-dir (directory with oci manifest type), docker-dir (directory with v2s2 manifest type)")
flags.StringVarP(&saveCommand.Output, "output", "o", "/dev/stdout", "Write to a file, default is STDOUT")
flags.BoolVarP(&saveCommand.Quiet, "quiet", "q", false, "Suppress the output")
}
@@ -64,7 +53,7 @@ func saveCmd(c *cliconfig.SaveValues) error {
return errors.Errorf("need at least 1 argument")
}
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not create runtime")
}
@@ -74,11 +63,6 @@ func saveCmd(c *cliconfig.SaveValues) error {
return errors.Errorf("--compress can only be set when --format is either 'oci-dir' or 'docker-dir'")
}
- var writer io.Writer
- if !c.Quiet {
- writer = os.Stderr
- }
-
output := c.Output
if output == "/dev/stdout" {
fi := os.Stdout
@@ -89,87 +73,5 @@ func saveCmd(c *cliconfig.SaveValues) error {
if err := validateFileName(output); err != nil {
return err
}
-
- source := args[0]
- newImage, err := runtime.ImageRuntime().NewFromLocal(source)
- if err != nil {
- return err
- }
-
- var destRef types.ImageReference
- var manifestType string
- switch c.Format {
- case "oci-archive":
- destImageName := imageNameForSaveDestination(newImage, source)
- 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":
- 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":
- destRef, err = directory.NewReference(output)
- if err != nil {
- return errors.Wrapf(err, "error getting directory ImageReference for %q", output)
- }
- manifestType = manifest.DockerV2Schema2MediaType
- case "docker-archive", "":
- 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"))
- }
-
- // supports saving multiple tags to the same tar archive
- var additionaltags []reference.NamedTagged
- if len(args) > 1 {
- additionaltags, err = libpodImage.GetAdditionalTags(args[1:])
- if err != nil {
- return err
- }
- }
- if err := newImage.PushImageToReference(getContext(), destRef, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, additionaltags); err != nil {
- if err2 := os.Remove(output); err2 != nil {
- logrus.Errorf("error deleting %q: %v", output, err)
- }
- return errors.Wrapf(err, "unable to save %q", args)
- }
-
- return nil
-}
-
-// imageNameForSaveDestination returns a Docker-like reference appropriate for saving img,
-// which the user referred to as imgUserInput; or an empty string, if there is no appropriate
-// reference.
-func imageNameForSaveDestination(img *libpodImage.Image, imgUserInput string) string {
- if strings.Contains(img.ID(), imgUserInput) {
- return ""
- }
-
- prepend := ""
- localRegistryPrefix := fmt.Sprintf("%s/", libpodImage.DefaultLocalRegistry)
- if !strings.HasPrefix(imgUserInput, localRegistryPrefix) {
- // we need to check if localhost was added to the image name in NewFromLocal
- for _, name := range img.Names() {
- // If the user is saving an image in the localhost registry, getLocalImage need
- // a name that matches the format localhost/<tag1>:<tag2> or localhost/<tag>:latest to correctly
- // set up the manifest and save.
- if strings.HasPrefix(name, localRegistryPrefix) && (strings.HasSuffix(name, imgUserInput) || strings.HasSuffix(name, fmt.Sprintf("%s:latest", imgUserInput))) {
- prepend = localRegistryPrefix
- break
- }
- }
- }
- return fmt.Sprintf("%s%s", prepend, imgUserInput)
+ return runtime.SaveImage(getContext(), c)
}
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index c53a5454a..cae77e5b3 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -26,6 +26,16 @@ type ContainerChanges (
deleted: []string
)
+type ImageSaveOptions (
+ name: string,
+ format: string,
+ output: string,
+ outputType: string,
+ moreTags: []string,
+ quiet: bool,
+ compress: bool
+)
+
type VolumeCreateOpts (
volumeName: string,
driver: string,
@@ -1090,6 +1100,8 @@ method GetVolumes(args: []string, all: bool) -> (volumes: []Volume)
# VolumesPrune removes unused volumes on the host
method VolumesPrune() -> (prunedNames: []string, prunedErrors: []string)
+method ImageSave(options: ImageSaveOptions) -> (reply: MoreResponse)
+
# ImageNotFound means the image could not be found by the provided name or ID in local storage.
error ImageNotFound (id: string)