mirror of
https://github.com/containers/podman.git
synced 2025-11-01 10:45:52 +08:00
migrate Podman to containers/common/libimage
Migrate the Podman code base over to `common/libimage` which replaces `libpod/image` and a lot of glue code entirely. Note that I tried to leave bread crumbs for changed tests. Miscellaneous changes: * Some errors yield different messages which required to alter some tests. * I fixed some pre-existing issues in the code. Others were marked as `//TODO`s to prevent the PR from exploding. * The `NamesHistory` of an image is returned as is from the storage. Previously, we did some filtering which I think is undesirable. Instead we should return the data as stored in the storage. * Touched handlers use the ABI interfaces where possible. * Local image resolution: previously Podman would match "foo" on "myfoo". This behaviour has been changed and Podman will now only match on repository boundaries such that "foo" would match "my/foo" but not "myfoo". I consider the old behaviour to be a bug, at the very least an exotic corner case. * Futhermore, "foo:none" does *not* resolve to a local image "foo" without tag anymore. It's a hill I am (almost) willing to die on. * `image prune` prints the IDs of pruned images. Previously, in some cases, the names were printed instead. The API clearly states ID, so we should stick to it. * Compat endpoint image removal with _force_ deletes the entire not only the specified tag. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
125
vendor/github.com/containers/common/libimage/load.go
generated
vendored
Normal file
125
vendor/github.com/containers/common/libimage/load.go
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
package libimage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
dirTransport "github.com/containers/image/v5/directory"
|
||||
dockerArchiveTransport "github.com/containers/image/v5/docker/archive"
|
||||
ociArchiveTransport "github.com/containers/image/v5/oci/archive"
|
||||
ociTransport "github.com/containers/image/v5/oci/layout"
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type LoadOptions struct {
|
||||
CopyOptions
|
||||
}
|
||||
|
||||
// Load loads one or more images (depending on the transport) from the
|
||||
// specified path. The path may point to an image the following transports:
|
||||
// oci, oci-archive, dir, docker-archive.
|
||||
func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) ([]string, error) {
|
||||
logrus.Debugf("Loading image from %q", path)
|
||||
|
||||
var (
|
||||
loadedImages []string
|
||||
loadError error
|
||||
)
|
||||
|
||||
if options == nil {
|
||||
options = &LoadOptions{}
|
||||
}
|
||||
|
||||
for _, f := range []func() ([]string, error){
|
||||
// OCI
|
||||
func() ([]string, error) {
|
||||
logrus.Debugf("-> Attempting to load %q as an OCI directory", path)
|
||||
ref, err := ociTransport.NewReference(path, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.copyFromDefault(ctx, ref, &options.CopyOptions)
|
||||
},
|
||||
|
||||
// OCI-ARCHIVE
|
||||
func() ([]string, error) {
|
||||
logrus.Debugf("-> Attempting to load %q as an OCI archive", path)
|
||||
ref, err := ociArchiveTransport.NewReference(path, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.copyFromDefault(ctx, ref, &options.CopyOptions)
|
||||
},
|
||||
|
||||
// DIR
|
||||
func() ([]string, error) {
|
||||
logrus.Debugf("-> Attempting to load %q as a Docker dir", path)
|
||||
ref, err := dirTransport.NewReference(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.copyFromDefault(ctx, ref, &options.CopyOptions)
|
||||
},
|
||||
|
||||
// DOCKER-ARCHIVE
|
||||
func() ([]string, error) {
|
||||
logrus.Debugf("-> Attempting to load %q as a Docker archive", path)
|
||||
ref, err := dockerArchiveTransport.ParseReference(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.loadMultiImageDockerArchive(ctx, ref, &options.CopyOptions)
|
||||
},
|
||||
|
||||
// Give a decent error message if nothing above worked.
|
||||
func() ([]string, error) {
|
||||
return nil, errors.New("payload does not match any of the supported image formats (oci, oci-archive, dir, docker-archive)")
|
||||
},
|
||||
} {
|
||||
loadedImages, loadError = f()
|
||||
if loadError == nil {
|
||||
return loadedImages, loadError
|
||||
}
|
||||
logrus.Debugf("Error loading %s: %v", path, loadError)
|
||||
}
|
||||
|
||||
return nil, loadError
|
||||
}
|
||||
|
||||
// loadMultiImageDockerArchive loads the docker archive specified by ref. In
|
||||
// case the path@reference notation was used, only the specifiec image will be
|
||||
// loaded. Otherwise, all images will be loaded.
|
||||
func (r *Runtime) loadMultiImageDockerArchive(ctx context.Context, ref types.ImageReference, options *CopyOptions) ([]string, error) {
|
||||
// If we cannot stat the path, it either does not exist OR the correct
|
||||
// syntax to reference an image within the archive was used, so we
|
||||
// should.
|
||||
path := ref.StringWithinTransport()
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
return r.copyFromDockerArchive(ctx, ref, options)
|
||||
}
|
||||
|
||||
reader, err := dockerArchiveTransport.NewReader(r.systemContextCopy(), path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
refLists, err := reader.List()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var copiedImages []string
|
||||
for _, list := range refLists {
|
||||
for _, listRef := range list {
|
||||
names, err := r.copyFromDockerArchiveReaderReference(ctx, reader, listRef, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
copiedImages = append(copiedImages, names...)
|
||||
}
|
||||
}
|
||||
|
||||
return copiedImages, nil
|
||||
}
|
||||
Reference in New Issue
Block a user