summaryrefslogtreecommitdiff
path: root/cmd/kpod
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2017-12-14 12:49:22 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-12-14 22:22:16 +0000
commitd2ab53aa5f67cb65a75f2c36fb076c0debd961ca (patch)
treea8c1a6ab01696beaae01169a810db132e5416971 /cmd/kpod
parent1e7d880b561318aa2ad89d7583addad1904e5a36 (diff)
downloadpodman-d2ab53aa5f67cb65a75f2c36fb076c0debd961ca.tar.gz
podman-d2ab53aa5f67cb65a75f2c36fb076c0debd961ca.tar.bz2
podman-d2ab53aa5f67cb65a75f2c36fb076c0debd961ca.zip
Add support for dir transport to kpod save
kpod save can now save images to directories using the dir transport. Manifest conversion is also possible. To save with the oci manifest type set --format to oci-dir and to save with the v2s2(docker) manifest type, set --format to docker-dir. The layers can be compressed as well when saving to a directory using the --compress flag. Added functionality to kpod load to be able to load image from a directory Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #137 Approved by: rhatdan
Diffstat (limited to 'cmd/kpod')
-rw-r--r--cmd/kpod/load.go12
-rw-r--r--cmd/kpod/save.go34
2 files changed, 39 insertions, 7 deletions
diff --git a/cmd/kpod/load.go b/cmd/kpod/load.go
index d29da0c06..5ae75a7a2 100644
--- a/cmd/kpod/load.go
+++ b/cmd/kpod/load.go
@@ -104,14 +104,18 @@ func loadCmd(c *cli.Context) error {
src := libpod.DockerArchive + ":" + input
imgName, err := runtime.PullImage(src, options)
if err != nil {
- src = libpod.OCIArchive + ":" + input
// generate full src name with specified image:tag
+ fullSrc := libpod.OCIArchive + ":" + input
if image != "" {
- src = src + ":" + image
+ fullSrc = fullSrc + ":" + image
}
- imgName, err = runtime.PullImage(src, options)
+ imgName, err = runtime.PullImage(fullSrc, options)
if err != nil {
- return errors.Wrapf(err, "error pulling %q", src)
+ src = libpod.DirTransport + ":" + input
+ imgName, err = runtime.PullImage(src, options)
+ if err != nil {
+ return errors.Wrapf(err, "error pulling %q", src)
+ }
}
}
fmt.Println("Loaded image: ", imgName)
diff --git a/cmd/kpod/save.go b/cmd/kpod/save.go
index 0f5fcfa4d..85a8c7930 100644
--- a/cmd/kpod/save.go
+++ b/cmd/kpod/save.go
@@ -3,15 +3,27 @@ package main
import (
"io"
"os"
+ "strings"
+ "github.com/containers/image/manifest"
+ imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
+const (
+ ociManifestDir = "oci-dir"
+ v2s2ManifestDir = "docker-dir"
+)
+
var (
saveFlags = []cli.Flag{
+ cli.BoolFlag{
+ Name: "compress",
+ Usage: "compress tarball image layers when saving to a directory using the 'dir' transport. (default is same compression type as source)",
+ },
cli.StringFlag{
Name: "output, o",
Usage: "Write to a file, default is STDOUT",
@@ -23,7 +35,7 @@ var (
},
cli.StringFlag{
Name: "format",
- Usage: "Save image to oci-archive",
+ Usage: "Save image to oci-archive, oci-dir (directory with oci manifest type), docker-dir (directory with v2s2 manifest type)",
},
}
saveDescription = `
@@ -56,6 +68,10 @@ func saveCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)
+ if c.IsSet("compress") && (c.String("format") != ociManifestDir && c.String("format") != v2s2ManifestDir && c.String("format") == "") {
+ return errors.Errorf("--compress can only be set when --format is either 'oci-dir' or 'docker-dir'")
+ }
+
var writer io.Writer
if !c.Bool("quiet") {
writer = os.Stdout
@@ -69,10 +85,16 @@ func saveCmd(c *cli.Context) error {
}
}
- var dst string
+ var dst, manifestType string
switch c.String("format") {
case libpod.OCIArchive:
dst = libpod.OCIArchive + ":" + output
+ case "oci-dir":
+ dst = libpod.DirTransport + ":" + output
+ manifestType = imgspecv1.MediaTypeImageManifest
+ case "docker-dir":
+ dst = libpod.DirTransport + ":" + output
+ manifestType = manifest.DockerV2Schema2MediaType
case libpod.DockerArchive:
fallthrough
case "":
@@ -84,12 +106,18 @@ func saveCmd(c *cli.Context) error {
saveOpts := libpod.CopyOptions{
SignaturePolicyPath: "",
Writer: writer,
+ ManifestMIMEType: manifestType,
+ ForceCompress: c.Bool("compress"),
}
// only one image is supported for now
// future pull requests will fix this
for _, image := range args {
- dest := dst + ":" + image
+ dest := dst
+ // need dest to be in the format transport:path:reference for the following transports
+ if strings.Contains(dst, libpod.OCIArchive) || strings.Contains(dst, libpod.DockerArchive) {
+ dest = dst + ":" + image
+ }
if err := runtime.PushImage(image, dest, saveOpts); err != nil {
if err2 := os.Remove(output); err2 != nil {
logrus.Errorf("error deleting %q: %v", output, err)