diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/load.go | 30 | ||||
-rw-r--r-- | cmd/podman/pull.go | 13 | ||||
-rw-r--r-- | cmd/podman/push.go | 7 | ||||
-rw-r--r-- | cmd/podman/save.go | 92 | ||||
-rw-r--r-- | cmd/podman/umount.go | 22 |
5 files changed, 109 insertions, 55 deletions
diff --git a/cmd/podman/load.go b/cmd/podman/load.go index 565b09184..ffef9f6a6 100644 --- a/cmd/podman/load.go +++ b/cmd/podman/load.go @@ -6,9 +6,11 @@ import ( "io/ioutil" "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/projectatomic/libpod/cmd/podman/libpodruntime" - "github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/image" "github.com/urfave/cli" ) @@ -45,10 +47,10 @@ var ( func loadCmd(c *cli.Context) error { args := c.Args() - var image string + var imageName string if len(args) == 1 { - image = args[0] + imageName = args[0] } if len(args) > 1 { return errors.New("too many arguments. Requires exactly 1") @@ -104,20 +106,24 @@ func loadCmd(c *cli.Context) error { ctx := getContext() - src := libpod.DockerArchive + ":" + input - newImages, err := runtime.ImageRuntime().LoadFromArchive(ctx, src, c.String("signature-policy"), writer) + var newImages []*image.Image + 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 { // generate full src name with specified image:tag - fullSrc := libpod.OCIArchive + ":" + input - if image != "" { - fullSrc = fullSrc + ":" + image + src, err := ociarchive.NewReference(input, imageName) // imageName may be "" + if err == nil { + 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 { - src = libpod.DirTransport + ":" + input - newImages, err = runtime.ImageRuntime().LoadFromArchive(ctx, src, c.String("signature-policy"), writer) + src, err := directory.NewReference(input) + if err == nil { + newImages, err = runtime.ImageRuntime().LoadFromArchiveReference(ctx, src, c.String("signature-policy"), writer) + } if err != nil { - return errors.Wrapf(err, "error pulling %q", src) + return errors.Wrapf(err, "error pulling %q", input) } } } diff --git a/cmd/podman/pull.go b/cmd/podman/pull.go index 431c1e0ed..a1d685735 100644 --- a/cmd/podman/pull.go +++ b/cmd/podman/pull.go @@ -6,10 +6,11 @@ import ( "os" "strings" + dockerarchive "github.com/containers/image/docker/archive" + "github.com/containers/image/transports/alltransports" "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" @@ -110,9 +111,13 @@ func pullCmd(c *cli.Context) error { forceSecure = c.Bool("tls-verify") } - // 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) + // Possible for docker-archive to have multiple tags, so use LoadFromArchiveReference instead + if strings.HasPrefix(image, dockerarchive.Transport.Name()+":") { + 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 { return errors.Wrapf(err, "error pulling image from %q", image) } diff --git a/cmd/podman/push.go b/cmd/podman/push.go index 74882adb2..3c2e59e58 100644 --- a/cmd/podman/push.go +++ b/cmd/podman/push.go @@ -6,12 +6,12 @@ import ( "os" "strings" + "github.com/containers/image/directory" "github.com/containers/image/manifest" "github.com/containers/image/types" imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" - "github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/image" "github.com/projectatomic/libpod/pkg/util" "github.com/urfave/cli" @@ -101,7 +101,7 @@ func pushCmd(c *cli.Context) error { // --compress and --format can only be used for the "dir" transport splitArg := strings.SplitN(destName, ":", 2) if c.IsSet("compress") || c.IsSet("format") { - if splitArg[0] != libpod.DirTransport { + if splitArg[0] != directory.Transport.Name() { return errors.Errorf("--compress and --format can be set only when pushing to a directory using the 'dir' transport") } } @@ -164,6 +164,5 @@ func pushCmd(c *cli.Context) error { return err } - //return runtime.PushImage(srcName, destName, options) - return newImage.PushImage(getContext(), destName, manifestType, c.String("authfile"), c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions, forceSecure, nil) + return newImage.PushImageToHeuristicDestination(getContext(), destName, manifestType, c.String("authfile"), c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions, forceSecure, nil) } diff --git a/cmd/podman/save.go b/cmd/podman/save.go index 016fa580a..6a0d12885 100644 --- a/cmd/podman/save.go +++ b/cmd/podman/save.go @@ -6,12 +6,15 @@ import ( "os" "strings" + "github.com/containers/image/directory" + dockerarchive "github.com/containers/image/docker/archive" "github.com/containers/image/docker/reference" "github.com/containers/image/manifest" + ociarchive "github.com/containers/image/oci/archive" + "github.com/containers/image/types" imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" - "github.com/projectatomic/libpod/libpod" libpodImage "github.com/projectatomic/libpod/libpod/image" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -93,20 +96,43 @@ func saveCmd(c *cli.Context) error { return err } - var dst, manifestType string + source := args[0] + newImage, err := runtime.ImageRuntime().NewFromLocal(source) + if err != nil { + return err + } + + var destRef types.ImageReference + var manifestType string switch c.String("format") { - case libpod.OCIArchive: - dst = libpod.OCIArchive + ":" + output + case "oci-archive": + destImageName := imageNameForSaveDestination(newImage, source) + destRef, err = ociarchive.NewReference(output, destImageName) // destImageName may be "" + if err != nil { + return errors.Wrapf(err, "error getting OCI archive ImageReference for (%q, %q)", output, destImageName) + } case "oci-dir": - dst = libpod.DirTransport + ":" + output + destRef, err = directory.NewReference(output) + if err != nil { + return errors.Wrapf(err, "error getting directory ImageReference for %q", output) + } manifestType = imgspecv1.MediaTypeImageManifest case "docker-dir": - dst = libpod.DirTransport + ":" + output + destRef, err = directory.NewReference(output) + if err != nil { + return errors.Wrapf(err, "error getting directory ImageReference for %q", output) + } manifestType = manifest.DockerV2Schema2MediaType - case libpod.DockerArchive: - fallthrough - case "": - dst = libpod.DockerArchive + ":" + output + case "docker-archive", "": + dst := output + destImageName := imageNameForSaveDestination(newImage, source) + if destImageName != "" { + dst = fmt.Sprintf("%s:%s", dst, destImageName) + } + destRef, err = dockerarchive.ParseReference(dst) // FIXME? Add dockerarchive.NewReference + if err != nil { + return errors.Wrapf(err, "error getting Docker archive ImageReference for %q", dst) + } default: return errors.Errorf("unknown format option %q", c.String("format")) } @@ -119,28 +145,8 @@ func saveCmd(c *cli.Context) error { return err } } - source := args[0] - newImage, err := runtime.ImageRuntime().NewFromLocal(source) - if err != nil { - return err - } - dest := dst - // need dest to be in the format transport:path:reference for the following transports - if (strings.Contains(dst, libpod.OCIArchive) || strings.Contains(dst, libpod.DockerArchive)) && !strings.Contains(newImage.ID(), source) { - prepend := "" - if !strings.Contains(source, libpodImage.DefaultLocalRepo) { - // we need to check if localhost was added to the image name in NewFromLocal - for _, name := range newImage.Names() { - // if the user searched for the image whose tag was prepended with localhost, we'll need to prepend localhost to successfully search - if strings.Contains(name, libpodImage.DefaultLocalRepo) && strings.Contains(name, source) { - prepend = fmt.Sprintf("%s/", libpodImage.DefaultLocalRepo) - break - } - } - } - dest = fmt.Sprintf("%s:%s%s", dst, prepend, source) - } - if err := newImage.PushImage(getContext(), dest, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false, additionaltags); err != nil { + + if err := newImage.PushImageToReference(getContext(), destRef, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false, additionaltags); err != nil { if err2 := os.Remove(output); err2 != nil { logrus.Errorf("error deleting %q: %v", output, err) } @@ -149,3 +155,25 @@ func saveCmd(c *cli.Context) error { return nil } + +// imageNameForSaveDestination returns a Docker-like reference appropriate for saving img, +// which the user referred to as imgUserInput; or an empty string, if there is no appropriate +// reference. +func imageNameForSaveDestination(img *libpodImage.Image, imgUserInput string) string { + if strings.Contains(img.ID(), imgUserInput) { + return "" + } + + prepend := "" + if !strings.Contains(imgUserInput, libpodImage.DefaultLocalRepo) { + // we need to check if localhost was added to the image name in NewFromLocal + for _, name := range img.Names() { + // if the user searched for the image whose tag was prepended with localhost, we'll need to prepend localhost to successfully search + if strings.Contains(name, libpodImage.DefaultLocalRepo) && strings.Contains(name, imgUserInput) { + prepend = fmt.Sprintf("%s/", libpodImage.DefaultLocalRepo) + break + } + } + } + return fmt.Sprintf("%s%s", prepend, imgUserInput) +} diff --git a/cmd/podman/umount.go b/cmd/podman/umount.go index 1a2cf22c6..1e364b48f 100644 --- a/cmd/podman/umount.go +++ b/cmd/podman/umount.go @@ -3,6 +3,7 @@ package main import ( "fmt" + "github.com/containers/storage" "github.com/pkg/errors" "github.com/projectatomic/libpod/cmd/podman/libpodruntime" "github.com/projectatomic/libpod/libpod" @@ -16,13 +17,24 @@ var ( Name: "all, a", Usage: "umount all of the currently mounted containers", }, + cli.BoolFlag{ + Name: "force, f", + Usage: "force the complete umount all of the currently mounted containers", + }, } + description = ` +Container storage increments a mount counter each time a container is mounted. +When a container is unmounted, the mount counter is decremented and the +container's root filesystem is physically unmounted only when the mount +counter reaches zero indicating no other processes are using the mount. +An unmount can be forced with the --force flag. +` umountCommand = cli.Command{ Name: "umount", Aliases: []string{"unmount"}, Usage: "Unmounts working container's root filesystem", - Description: "Unmounts working container's root filesystem", + Description: description, Flags: umountFlags, Action: umountCmd, ArgsUsage: "CONTAINER-NAME-OR-ID", @@ -36,6 +48,7 @@ func umountCmd(c *cli.Context) error { } defer runtime.Shutdown(false) + force := c.Bool("force") umountAll := c.Bool("all") args := c.Args() if len(args) == 0 && !umountAll { @@ -58,7 +71,7 @@ func umountCmd(c *cli.Context) error { continue } - if err = ctr.Unmount(); err != nil { + if err = ctr.Unmount(force); err != nil { if lastError != nil { logrus.Error(lastError) } @@ -78,7 +91,10 @@ func umountCmd(c *cli.Context) error { continue } - if err = ctr.Unmount(); err != nil { + if err = ctr.Unmount(force); err != nil { + if umountAll && errors.Cause(err) == storage.ErrLayerNotMounted { + continue + } if lastError != nil { logrus.Error(lastError) } |