Begin converting kpod pull to use libpod/runtime
We want to drop brute force mechainism for handling image movement, this patch experiments with moving kpod pull to use new libpod interfaces. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
e18e962238
commit
9f282717da
5 changed files with 31 additions and 30 deletions
|
@ -8,7 +8,9 @@ import (
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
"github.com/fatih/camelcase"
|
"github.com/fatih/camelcase"
|
||||||
"github.com/kubernetes-incubator/cri-o/libkpod"
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/libpod"
|
||||||
"github.com/kubernetes-incubator/cri-o/server"
|
"github.com/kubernetes-incubator/cri-o/server"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,6 +34,22 @@ func getStore(c *libkpod.Config) (storage.Store, error) {
|
||||||
return store, nil
|
return store, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getRuntime(c *cli.Context) (*libpod.Runtime, error) {
|
||||||
|
|
||||||
|
config, err := getConfig(c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "could not get config")
|
||||||
|
}
|
||||||
|
|
||||||
|
options := storage.DefaultStoreOptions
|
||||||
|
options.GraphRoot = config.Root
|
||||||
|
options.RunRoot = config.RunRoot
|
||||||
|
options.GraphDriverName = config.Storage
|
||||||
|
options.GraphDriverOptions = config.StorageOptions
|
||||||
|
|
||||||
|
return libpod.NewRuntime(libpod.WithStorageConfig(options))
|
||||||
|
}
|
||||||
|
|
||||||
func shutdownStores() {
|
func shutdownStores() {
|
||||||
for store := range stores {
|
for store := range stores {
|
||||||
if _, err := store.Shutdown(false); err != nil {
|
if _, err := store.Shutdown(false); err != nil {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kubernetes-incubator/cri-o/libkpod/common"
|
"os"
|
||||||
"github.com/kubernetes-incubator/cri-o/libpod/images"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -45,21 +45,11 @@ func pullCmd(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
image := args[0]
|
image := args[0]
|
||||||
|
|
||||||
config, err := getConfig(c)
|
runtime, err := getRuntime(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not get config")
|
return errors.Wrapf(err, "could not create runtime")
|
||||||
}
|
}
|
||||||
store, err := getStore(config)
|
if err := runtime.PullImage(image, c.Bool("all-tags"), os.Stdout); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
allTags := c.Bool("all-tags")
|
|
||||||
|
|
||||||
systemContext := common.GetSystemContext("")
|
|
||||||
|
|
||||||
err = images.PullImage(store, image, allTags, false, systemContext)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Errorf("error pulling image from %q: %v", image, err)
|
return errors.Errorf("error pulling image from %q: %v", image, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
"github.com/kubernetes-incubator/cri-o/libkpod/common"
|
"github.com/kubernetes-incubator/cri-o/libpod/common"
|
||||||
"github.com/kubernetes-incubator/cri-o/libpod/images"
|
"github.com/kubernetes-incubator/cri-o/libpod/images"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -103,7 +103,7 @@ func pushCmd(c *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
options := libkpodimage.CopyOptions{
|
options := images.CopyOptions{
|
||||||
Compression: archive.Uncompressed,
|
Compression: archive.Uncompressed,
|
||||||
SignaturePolicyPath: signaturePolicy,
|
SignaturePolicyPath: signaturePolicy,
|
||||||
Store: store,
|
Store: store,
|
||||||
|
|
|
@ -33,11 +33,6 @@ type CopyOptions struct {
|
||||||
// layer blobs. The default is to not use compression, but
|
// layer blobs. The default is to not use compression, but
|
||||||
// archive.Gzip is recommended.
|
// archive.Gzip is recommended.
|
||||||
Compression archive.Compression
|
Compression archive.Compression
|
||||||
// ReportWriter is an io.Writer which will be used to log the writing
|
|
||||||
// of the new image.
|
|
||||||
ReportWriter io.Writer
|
|
||||||
// Store is the local storage store which holds the source image.
|
|
||||||
Store storage.Store
|
|
||||||
// DockerRegistryOptions encapsulates settings that affect how we
|
// DockerRegistryOptions encapsulates settings that affect how we
|
||||||
// connect or authenticate to a remote registry to which we want to
|
// connect or authenticate to a remote registry to which we want to
|
||||||
// push the image.
|
// push the image.
|
||||||
|
@ -60,7 +55,7 @@ type ImageFilter func(*storage.Image) bool
|
||||||
// pulled. If allTags is true, all tags for the requested image will be pulled.
|
// pulled. If allTags is true, all tags for the requested image will be pulled.
|
||||||
// Signature validation will be performed if the Runtime has been appropriately
|
// Signature validation will be performed if the Runtime has been appropriately
|
||||||
// configured
|
// configured
|
||||||
func (r *Runtime) PullImage(imgName string, allTags bool) error {
|
func (r *Runtime) PullImage(imgName string, allTags bool, reportWriter io.Writer) error {
|
||||||
// PullImage copies the image from the source to the destination
|
// PullImage copies the image from the source to the destination
|
||||||
var (
|
var (
|
||||||
images []string
|
images []string
|
||||||
|
@ -123,7 +118,7 @@ func (r *Runtime) PullImage(imgName string, allTags bool) error {
|
||||||
}
|
}
|
||||||
defer policyContext.Destroy()
|
defer policyContext.Destroy()
|
||||||
|
|
||||||
copyOptions := common.GetCopyOptions(r.output, "", nil, nil, common.SigningOptions{})
|
copyOptions := common.GetCopyOptions(reportWriter, "", nil, nil, common.SigningOptions{})
|
||||||
|
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
destRef, err := is.Transport.ParseStoreReference(r.store, image)
|
destRef, err := is.Transport.ParseStoreReference(r.store, image)
|
||||||
|
@ -138,7 +133,7 @@ func (r *Runtime) PullImage(imgName string, allTags bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushImage pushes the given image to a location described by the given path
|
// PushImage pushes the given image to a location described by the given path
|
||||||
func (r *Runtime) PushImage(source string, destination string, options CopyOptions) error {
|
func (r *Runtime) PushImage(source string, destination string, options CopyOptions, reportWriter io.Writer) error {
|
||||||
// PushImage pushes the src image to the destination
|
// PushImage pushes the src image to the destination
|
||||||
//func PushImage(source, destination string, options CopyOptions) error {
|
//func PushImage(source, destination string, options CopyOptions) error {
|
||||||
if source == "" || destination == "" {
|
if source == "" || destination == "" {
|
||||||
|
@ -151,9 +146,9 @@ func (r *Runtime) PushImage(source string, destination string, options CopyOptio
|
||||||
return errors.Wrapf(err, "error getting destination imageReference for %q", destination)
|
return errors.Wrapf(err, "error getting destination imageReference for %q", destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
policyContext, err := common.GetPolicyContext(options.SignaturePolicyPath)
|
policyContext, err := common.GetPolicyContext(r.GetConfig().SignaturePolicyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Could not get default policy context for signature policy path %q", options.SignaturePolicyPath)
|
return errors.Wrapf(err, "Could not get default policy context for signature policy path %q", r.GetConfig().SignaturePolicyPath)
|
||||||
}
|
}
|
||||||
defer policyContext.Destroy()
|
defer policyContext.Destroy()
|
||||||
// Look up the image name and its layer, then build the imagePushData from
|
// Look up the image name and its layer, then build the imagePushData from
|
||||||
|
@ -176,7 +171,7 @@ func (r *Runtime) PushImage(source string, destination string, options CopyOptio
|
||||||
return errors.Wrapf(err, "error copying layers and metadata")
|
return errors.Wrapf(err, "error copying layers and metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
copyOptions := common.GetCopyOptions(options.ReportWriter, options.SignaturePolicyPath, nil, &options.DockerRegistryOptions, options.SigningOptions)
|
copyOptions := common.GetCopyOptions(reportWriter, r.GetConfig().SignaturePolicyPath, nil, &options.DockerRegistryOptions, options.SigningOptions)
|
||||||
|
|
||||||
// Copy the image to the remote destination
|
// Copy the image to the remote destination
|
||||||
err = cp.Image(policyContext, dest, src, copyOptions)
|
err = cp.Image(policyContext, dest, src, copyOptions)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
|
@ -29,7 +28,6 @@ type Runtime struct {
|
||||||
seccompEnabled bool
|
seccompEnabled bool
|
||||||
valid bool
|
valid bool
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
output io.Writer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RuntimeConfig contains configuration options used to set up the runtime
|
// RuntimeConfig contains configuration options used to set up the runtime
|
||||||
|
|
Loading…
Add table
Reference in a new issue