2017-06-30 19:10:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Sirupsen/logrus"
|
2017-07-23 23:01:37 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/libkpod/common"
|
2017-07-23 23:12:36 +00:00
|
|
|
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
|
2017-06-30 19:10:57 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
pullFlags = []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
// all-tags is hidden since it has not been implemented yet
|
|
|
|
Name: "all-tags, a",
|
|
|
|
Hidden: true,
|
|
|
|
Usage: "Download all tagged images in the repository",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
pullDescription = "Pulls an image from a registry and stores it locally.\n" +
|
|
|
|
"An image can be pulled using its tag or digest. If a tag is not\n" +
|
|
|
|
"specified, the image with the 'latest' tag (if it exists) is pulled."
|
|
|
|
pullCommand = cli.Command{
|
|
|
|
Name: "pull",
|
|
|
|
Usage: "pull an image from a registry",
|
|
|
|
Description: pullDescription,
|
|
|
|
Flags: pullFlags,
|
|
|
|
Action: pullCmd,
|
|
|
|
ArgsUsage: "",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// pullCmd gets the data from the command line and calls pullImage
|
|
|
|
// to copy an image from a registry to a local machine
|
|
|
|
func pullCmd(c *cli.Context) error {
|
|
|
|
args := c.Args()
|
|
|
|
if len(args) == 0 {
|
|
|
|
logrus.Errorf("an image name must be specified")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if len(args) > 1 {
|
|
|
|
logrus.Errorf("too many arguments. Requires exactly 1")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
image := args[0]
|
|
|
|
|
2017-07-27 17:18:07 +00:00
|
|
|
config, err := getConfig(c)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "could not get config")
|
|
|
|
}
|
|
|
|
store, err := getStore(config)
|
2017-06-30 19:10:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
allTags := false
|
|
|
|
if c.IsSet("all-tags") {
|
|
|
|
allTags = c.Bool("all-tags")
|
|
|
|
}
|
|
|
|
|
2017-07-23 23:01:37 +00:00
|
|
|
systemContext := common.GetSystemContext("")
|
2017-06-30 19:10:57 +00:00
|
|
|
|
2017-07-23 23:12:36 +00:00
|
|
|
err = libkpodimage.PullImage(store, image, allTags, systemContext)
|
2017-06-30 19:10:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Errorf("error pulling image from %q: %v", image, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|