Merge pull request #830 from umohnani8/update_load-save

Update kpod load and save for oci-archive
This commit is contained in:
Daniel J Walsh 2017-09-09 05:58:54 -04:00 committed by GitHub
commit 36584e6f34
8 changed files with 126 additions and 33 deletions

View file

@ -7,7 +7,6 @@ import (
"io/ioutil"
"github.com/containers/storage"
"github.com/kubernetes-incubator/cri-o/libpod/common"
"github.com/kubernetes-incubator/cri-o/libpod/images"
"github.com/pkg/errors"
"github.com/urfave/cli"
@ -16,6 +15,7 @@ import (
type loadOptions struct {
input string
quiet bool
image string
}
var (
@ -54,12 +54,15 @@ func loadCmd(c *cli.Context) error {
}
args := c.Args()
if len(args) > 0 {
var image string
if len(args) == 1 {
image = args[0]
}
if len(args) > 1 {
return errors.New("too many arguments. Requires exactly 1")
}
input := c.String("input")
quiet := c.Bool("quiet")
if input == "/dev/stdin" {
fi, err := os.Stdin.Stat()
@ -92,7 +95,8 @@ func loadCmd(c *cli.Context) error {
opts := loadOptions{
input: input,
quiet: quiet,
quiet: c.Bool("quiet"),
image: image,
}
return loadImage(store, opts)
@ -101,9 +105,21 @@ func loadCmd(c *cli.Context) error {
// loadImage loads the image from docker-archive or oci to containers-storage
// using the pullImage function
func loadImage(store storage.Store, opts loadOptions) error {
systemContext := common.GetSystemContext("")
loadOpts := images.CopyOptions{
Quiet: opts.quiet,
Store: store,
}
src := dockerArchive + opts.input
return images.PullImage(store, src, false, opts.quiet, systemContext)
src := images.DockerArchive + ":" + opts.input
if err := images.PullImage(src, false, loadOpts); err != nil {
src = images.OCIArchive + ":" + opts.input
// generate full src name with specified image:tag
if opts.image != "" {
src = src + ":" + opts.image
}
if err := images.PullImage(src, false, loadOpts); err != nil {
return errors.Wrapf(err, "error pulling from %q", opts.input)
}
}
return nil
}

View file

@ -10,13 +10,10 @@ import (
"github.com/urfave/cli"
)
const (
dockerArchive = "docker-archive:"
)
type saveOptions struct {
output string
quiet bool
format string
images []string
}
@ -31,9 +28,16 @@ var (
Name: "quiet, q",
Usage: "Suppress the output",
},
cli.StringFlag{
Name: "format",
Usage: "Save image to oci-archive",
},
}
saveDescription = "Save an image to docker-archive on the local machine"
saveCommand = cli.Command{
saveDescription = `
Save an image to docker-archive or oci-archive on the local machine.
Default is docker-archive`
saveCommand = cli.Command{
Name: "save",
Usage: "Save image to an archive",
Description: saveDescription,
@ -60,7 +64,6 @@ func saveCmd(c *cli.Context) error {
}
output := c.String("output")
quiet := c.Bool("quiet")
if output == "/dev/stdout" {
fi := os.Stdout
@ -71,7 +74,8 @@ func saveCmd(c *cli.Context) error {
opts := saveOptions{
output: output,
quiet: quiet,
quiet: c.Bool("quiet"),
format: c.String("format"),
images: args,
}
@ -81,9 +85,19 @@ func saveCmd(c *cli.Context) error {
// saveImage pushes the image to docker-archive or oci by
// calling pushImage
func saveImage(store storage.Store, opts saveOptions) error {
dst := dockerArchive + opts.output
var dst string
switch opts.format {
case images.OCIArchive:
dst = images.OCIArchive + ":" + opts.output
case images.DockerArchive:
fallthrough
case "":
dst = images.DockerArchive + ":" + opts.output
default:
return errors.Errorf("unknown format option %q", opts.format)
}
pushOpts := images.CopyOptions{
saveOpts := images.CopyOptions{
SignaturePolicyPath: "",
Store: store,
}
@ -92,7 +106,7 @@ func saveImage(store storage.Store, opts saveOptions) error {
// future pull requests will fix this
for _, image := range opts.images {
dest := dst + ":" + image
if err := images.PushImage(image, dest, pushOpts); err != nil {
if err := images.PushImage(image, dest, saveOpts); err != nil {
return errors.Wrapf(err, "unable to save %q", image)
}
}