Update kpod load and save for oci-archive
Signed-off-by: umohnani8 <umohnani@redhat.com>
This commit is contained in:
parent
f9387aca28
commit
79c09d4343
8 changed files with 126 additions and 33 deletions
|
@ -7,12 +7,13 @@ import (
|
|||
"syscall"
|
||||
|
||||
cp "github.com/containers/image/copy"
|
||||
dockerarchive "github.com/containers/image/docker/archive"
|
||||
"github.com/containers/image/docker/tarfile"
|
||||
"github.com/containers/image/manifest"
|
||||
ociarchive "github.com/containers/image/oci/archive"
|
||||
"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/containers/storage/pkg/archive"
|
||||
"github.com/kubernetes-incubator/cri-o/libpod/common"
|
||||
|
@ -25,6 +26,15 @@ const (
|
|||
DefaultRegistry = "docker://"
|
||||
)
|
||||
|
||||
var (
|
||||
// DockerArchive is the transport we prepend to an image name
|
||||
// when saving to docker-archive
|
||||
DockerArchive = dockerarchive.Transport.Name()
|
||||
// OCIArchive is the transport we prepend to an image name
|
||||
// when saving to oci-archive
|
||||
OCIArchive = ociarchive.Transport.Name()
|
||||
)
|
||||
|
||||
// CopyOptions contains the options given when pushing or pulling images
|
||||
type CopyOptions struct {
|
||||
// Compression specifies the type of compression which is applied to
|
||||
|
@ -50,6 +60,8 @@ type CopyOptions struct {
|
|||
// strip or add signatures to the image when pushing (uploading) the
|
||||
// image to a registry.
|
||||
common.SigningOptions
|
||||
// Quiet suppresses the output when a push or pull happens
|
||||
Quiet bool
|
||||
}
|
||||
|
||||
// PushImage pushes the src image to the destination
|
||||
|
@ -101,13 +113,15 @@ func PushImage(srcName, destName string, options CopyOptions) error {
|
|||
}
|
||||
|
||||
// PullImage copies the image from the source to the destination
|
||||
func PullImage(store storage.Store, imgName string, allTags, quiet bool, sc *types.SystemContext) error {
|
||||
func PullImage(imgName string, allTags bool, options CopyOptions) error {
|
||||
var (
|
||||
images []string
|
||||
output io.Writer
|
||||
)
|
||||
store := options.Store
|
||||
sc := common.GetSystemContext(options.SignaturePolicyPath)
|
||||
|
||||
if quiet {
|
||||
if options.Quiet {
|
||||
output = nil
|
||||
} else {
|
||||
output = os.Stdout
|
||||
|
@ -124,10 +138,11 @@ func PullImage(store storage.Store, imgName string, allTags, quiet bool, sc *typ
|
|||
}
|
||||
|
||||
splitArr := strings.Split(imgName, ":")
|
||||
archFile := splitArr[len(splitArr)-1]
|
||||
|
||||
// supports pulling from docker-archive, oci, and registries
|
||||
if splitArr[0] == "docker-archive" {
|
||||
tarSource := tarfile.NewSource(splitArr[len(splitArr)-1])
|
||||
if srcRef.Transport().Name() == DockerArchive {
|
||||
tarSource := tarfile.NewSource(archFile)
|
||||
manifest, err := tarSource.LoadTarManifest()
|
||||
if err != nil {
|
||||
return errors.Errorf("error retrieving manifest.json: %v", err)
|
||||
|
@ -152,9 +167,17 @@ func PullImage(store storage.Store, imgName string, allTags, quiet bool, sc *typ
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if splitArr[0] == "oci" {
|
||||
// needs to be implemented in future
|
||||
return errors.Errorf("oci not supported")
|
||||
} else if srcRef.Transport().Name() == OCIArchive {
|
||||
// retrieve the manifest from index.json to access the image name
|
||||
manifest, err := ociarchive.LoadManifestDescriptor(srcRef)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error loading manifest for %q", srcRef)
|
||||
}
|
||||
|
||||
if manifest.Annotations == nil || manifest.Annotations["org.opencontainers.image.ref.name"] == "" {
|
||||
return errors.Errorf("error, archive doesn't have a name annotation. Cannot store image with no name")
|
||||
}
|
||||
images = append(images, manifest.Annotations["org.opencontainers.image.ref.name"])
|
||||
} else {
|
||||
images = append(images, imgName)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue