mirror of
https://github.com/containers/podman.git
synced 2025-06-28 14:29:04 +08:00
Replace Runtime.LoadFromArchive with Runtime.LoadFromArchiveReference
All callers of LoadFromArchive expect the input to be in the transport:name format, or create it that way. So, pass a types.ImageReference instead of a string. That requires us to add an explicit parse step in (podman pull); in (podman load) we can, instead of pasting strings, create native objects directly. Changes the error behavior of (podman pull), we no longer try heuristically parsing docker-archive:... inputs as Docker references. Also changes the string reported by (podman load) if all parsing attempts fail, to be only the path instead of dir:path. The error message itself is likely to be the same (from directory.Transport). (While at it, update a mismatched comment.) Signed-off-by: Miloslav Trmač <mitr@redhat.com> Closes: #1176 Approved by: rhatdan
This commit is contained in:

committed by
Atomic Bot

parent
04f3a9079c
commit
5507f15ba5
@ -6,9 +6,11 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/containers/image/directory"
|
||||||
|
dockerarchive "github.com/containers/image/docker/archive"
|
||||||
|
ociarchive "github.com/containers/image/oci/archive"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/projectatomic/libpod/libpod"
|
|
||||||
"github.com/projectatomic/libpod/libpod/image"
|
"github.com/projectatomic/libpod/libpod/image"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -104,20 +106,24 @@ func loadCmd(c *cli.Context) error {
|
|||||||
|
|
||||||
ctx := getContext()
|
ctx := getContext()
|
||||||
|
|
||||||
src := libpod.DockerArchive + ":" + input
|
var newImages []*image.Image
|
||||||
newImages, err := runtime.ImageRuntime().LoadFromArchive(ctx, src, c.String("signature-policy"), writer)
|
src, err := dockerarchive.ParseReference(input) // FIXME? We should add dockerarchive.NewReference()
|
||||||
|
if err == nil {
|
||||||
|
newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// generate full src name with specified image:tag
|
// generate full src name with specified image:tag
|
||||||
fullSrc := libpod.OCIArchive + ":" + input
|
src, err := ociarchive.NewReference(input, imageName) // imageName may be ""
|
||||||
if imageName != "" {
|
if err == nil {
|
||||||
fullSrc = fullSrc + ":" + imageName
|
newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer)
|
||||||
}
|
}
|
||||||
newImages, err = runtime.ImageRuntime().LoadFromArchive(ctx, fullSrc, c.String("signature-policy"), writer)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
src = libpod.DirTransport + ":" + input
|
src, err := directory.NewReference(input)
|
||||||
newImages, err = runtime.ImageRuntime().LoadFromArchive(ctx, src, c.String("signature-policy"), writer)
|
if err == nil {
|
||||||
|
newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error pulling %q", src)
|
return errors.Wrapf(err, "error pulling %q", input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/image/transports/alltransports"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
"github.com/projectatomic/libpod/cmd/podman/libpodruntime"
|
||||||
@ -110,9 +111,13 @@ func pullCmd(c *cli.Context) error {
|
|||||||
forceSecure = c.Bool("tls-verify")
|
forceSecure = c.Bool("tls-verify")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possible for docker-archive to have multiple tags, so use NewFromLoad instead
|
// Possible for docker-archive to have multiple tags, so use LoadFromArchiveReference instead
|
||||||
if strings.HasPrefix(image, libpod.DockerArchive+":") {
|
if strings.HasPrefix(image, libpod.DockerArchive+":") {
|
||||||
newImage, err := runtime.ImageRuntime().LoadFromArchive(getContext(), image, c.String("signature-policy"), writer)
|
srcRef, err := alltransports.ParseImageName(image)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "error parsing %q", image)
|
||||||
|
}
|
||||||
|
newImage, err := runtime.ImageRuntime().LoadFromArchiveReference(getContext(), srcRef, c.String("signature-policy"), writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error pulling image from %q", image)
|
return errors.Wrapf(err, "error pulling image from %q", image)
|
||||||
}
|
}
|
||||||
|
@ -159,17 +159,17 @@ func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile
|
|||||||
return &newImage, nil
|
return &newImage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFromArchive creates a new image object for images pulled from a tar archive (podman load)
|
// LoadFromArchiveReference creates a new image object for images pulled from a tar archive and the like (podman load)
|
||||||
// This function is needed because it is possible for a tar archive to have multiple tags for one image
|
// This function is needed because it is possible for a tar archive to have multiple tags for one image
|
||||||
func (ir *Runtime) LoadFromArchive(ctx context.Context, name, signaturePolicyPath string, writer io.Writer) ([]*Image, error) {
|
func (ir *Runtime) LoadFromArchiveReference(ctx context.Context, srcRef types.ImageReference, signaturePolicyPath string, writer io.Writer) ([]*Image, error) {
|
||||||
var newImages []*Image
|
var newImages []*Image
|
||||||
|
|
||||||
if signaturePolicyPath == "" {
|
if signaturePolicyPath == "" {
|
||||||
signaturePolicyPath = ir.SignaturePolicyPath
|
signaturePolicyPath = ir.SignaturePolicyPath
|
||||||
}
|
}
|
||||||
imageNames, err := ir.pullImage(ctx, name, writer, "", signaturePolicyPath, SigningOptions{}, &DockerRegistryOptions{}, false)
|
imageNames, err := ir.pullImage(ctx, transports.ImageName(srcRef), writer, "", signaturePolicyPath, SigningOptions{}, &DockerRegistryOptions{}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "unable to pull %s", name)
|
return nil, errors.Wrapf(err, "unable to pull %s", transports.ImageName(srcRef))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range imageNames {
|
for _, name := range imageNames {
|
||||||
|
Reference in New Issue
Block a user