move PushImage and PullImage to libkpod/image
Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
parent
14864f820e
commit
df7536e3c0
5 changed files with 163 additions and 154 deletions
|
@ -1,28 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
cp "github.com/containers/image/copy"
|
||||
"github.com/containers/image/docker/reference"
|
||||
"github.com/containers/image/signature"
|
||||
is "github.com/containers/image/storage"
|
||||
"github.com/containers/image/transports/alltransports"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/containers/storage"
|
||||
"github.com/kubernetes-incubator/cri-o/libkpod/common"
|
||||
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultRegistry is a prefix that we apply to an image name
|
||||
// to check docker hub first for the image
|
||||
DefaultRegistry = "docker://"
|
||||
)
|
||||
|
||||
var (
|
||||
pullFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
|
@ -72,57 +57,9 @@ func pullCmd(c *cli.Context) error {
|
|||
|
||||
systemContext := common.GetSystemContext("")
|
||||
|
||||
err = pullImage(store, image, allTags, systemContext)
|
||||
err = libkpodimage.PullImage(store, image, allTags, systemContext)
|
||||
if err != nil {
|
||||
return errors.Errorf("error pulling image from %q: %v", image, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// pullImage copies the image from the source to the destination
|
||||
func pullImage(store storage.Store, imgName string, allTags bool, sc *types.SystemContext) error {
|
||||
defaultName := DefaultRegistry + imgName
|
||||
var fromName string
|
||||
var tag string
|
||||
|
||||
srcRef, err := alltransports.ParseImageName(defaultName)
|
||||
if err != nil {
|
||||
srcRef2, err2 := alltransports.ParseImageName(imgName)
|
||||
if err2 != nil {
|
||||
return errors.Wrapf(err2, "error parsing image name %q", imgName)
|
||||
}
|
||||
srcRef = srcRef2
|
||||
}
|
||||
|
||||
ref := srcRef.DockerReference()
|
||||
if ref != nil {
|
||||
imgName = srcRef.DockerReference().Name()
|
||||
fromName = imgName
|
||||
tagged, ok := srcRef.DockerReference().(reference.NamedTagged)
|
||||
if ok {
|
||||
imgName = imgName + ":" + tagged.Tag()
|
||||
tag = tagged.Tag()
|
||||
}
|
||||
}
|
||||
|
||||
destRef, err := is.Transport.ParseStoreReference(store, imgName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error parsing full image name %q", imgName)
|
||||
}
|
||||
|
||||
policy, err := signature.DefaultPolicy(sc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
policyContext, err := signature.NewPolicyContext(policy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer policyContext.Destroy()
|
||||
|
||||
copyOptions := common.GetCopyOptions(os.Stdout, "", nil, nil, common.SigningOptions{})
|
||||
|
||||
fmt.Println(tag + ": pulling from " + fromName)
|
||||
return cp.Image(policyContext, destRef, srcRef, copyOptions)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue