From c8b72e57a75262c0edeea839e9e34bb0c3e03d13 Mon Sep 17 00:00:00 2001 From: umohnani8 Date: Mon, 21 May 2018 13:53:19 -0400 Subject: save and load should support multi-tag for docker-archive The docker-archive tar files can have multiple tags for the same image stored in it. Load pulls all the tags found in the archive when loading a tar file. Save can oush multiple tags of the same image to a tar archive. Signed-off-by: umohnani8 Closes: #819 Approved by: rhatdan --- cmd/podman/pull.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'cmd/podman/pull.go') diff --git a/cmd/podman/pull.go b/cmd/podman/pull.go index 521492dc5..a1e99fce2 100644 --- a/cmd/podman/pull.go +++ b/cmd/podman/pull.go @@ -1,14 +1,15 @@ package main import ( + "fmt" "io" "os" - - "fmt" + "strings" "github.com/containers/image/types" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" + "github.com/projectatomic/libpod/libpod" image2 "github.com/projectatomic/libpod/libpod/image" "github.com/projectatomic/libpod/pkg/util" "github.com/sirupsen/logrus" @@ -90,7 +91,10 @@ func pullCmd(c *cli.Context) error { registryCreds = creds } - var writer io.Writer + var ( + writer io.Writer + imgID string + ) if !c.Bool("quiet") { writer = os.Stderr } @@ -104,13 +108,23 @@ func pullCmd(c *cli.Context) error { forceSecure = c.Bool("tls-verify") } - newImage, err := runtime.ImageRuntime().New(getContext(), image, c.String("signature-policy"), c.String("authfile"), writer, &dockerRegistryOptions, image2.SigningOptions{}, true, forceSecure) - if err != nil { - return errors.Wrapf(err, "error pulling image %q", image) + // Possible for docker-archive to have multiple tags, so use NewFromLoad instead + if strings.Contains(image, libpod.DockerArchive) { + newImage, err := runtime.ImageRuntime().LoadFromArchive(getContext(), image, c.String("signature-policy"), writer) + if err != nil { + return errors.Wrapf(err, "error pulling image from %q", image) + } + imgID = newImage[0].ID() + } else { + newImage, err := runtime.ImageRuntime().New(getContext(), image, c.String("signature-policy"), c.String("authfile"), writer, &dockerRegistryOptions, image2.SigningOptions{}, true, forceSecure) + if err != nil { + return errors.Wrapf(err, "error pulling image %q", image) + } + imgID = newImage.ID() } // Intentionally choosing to ignore if there is an error because // outputting the image ID is a NTH and not integral to the pull - fmt.Println(newImage.ID()) + fmt.Println(imgID) return nil } -- cgit v1.2.3-54-g00ecf