diff options
author | baude <bbaude@redhat.com> | 2018-03-15 10:06:49 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-03-20 16:20:12 +0000 |
commit | 38a1b2f16d210525eafcc845e7a9cce598207113 (patch) | |
tree | 5616a12d68ebe55138fbde85f936a6bc90d4c8fd /cmd/podman | |
parent | ecfa321288f10b70a59166f93296c77d262317fc (diff) | |
download | podman-38a1b2f16d210525eafcc845e7a9cce598207113.tar.gz podman-38a1b2f16d210525eafcc845e7a9cce598207113.tar.bz2 podman-38a1b2f16d210525eafcc845e7a9cce598207113.zip |
Image library stage 4 - create and commit
Migrate the podman create and commit subcommandis to leverage the images library. I also had
to migrate the cmd/ portions of run and rmi.
Signed-off-by: baude <bbaude@redhat.com>
Closes: #498
Approved by: mheon
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/commit.go | 20 | ||||
-rw-r--r-- | cmd/podman/create.go | 61 | ||||
-rw-r--r-- | cmd/podman/history.go | 11 | ||||
-rw-r--r-- | cmd/podman/import.go | 22 | ||||
-rw-r--r-- | cmd/podman/inspect.go | 16 | ||||
-rw-r--r-- | cmd/podman/rmi.go | 28 | ||||
-rw-r--r-- | cmd/podman/run.go | 9 |
7 files changed, 74 insertions, 93 deletions
diff --git a/cmd/podman/commit.go b/cmd/podman/commit.go index 59ced293f..34a086004 100644 --- a/cmd/podman/commit.go +++ b/cmd/podman/commit.go @@ -2,11 +2,12 @@ package main import ( "fmt" + "io" "os" "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/libpod/image" "github.com/urfave/cli" ) @@ -58,8 +59,11 @@ func commitCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - var opts libpod.CopyOptions - var container string + var ( + container string + reference string + writer io.Writer + ) args := c.Args() switch len(args) { case 0: @@ -68,7 +72,7 @@ func commitCmd(c *cli.Context) error { container = args[0] case 2: container = args[0] - opts.Reference = args[1] + reference = args[1] default: return errors.Errorf("too many arguments. Usage CONTAINER [REFERENCE]") } @@ -90,20 +94,18 @@ func commitCmd(c *cli.Context) error { History: history, Author: c.String("author"), } - opts.ImageConfig = config - opts.Writer = nil if !c.Bool("quiet") { - opts.Writer = os.Stderr + writer = os.Stderr } ctr, err := runtime.LookupContainer(container) if err != nil { return errors.Wrapf(err, "error looking up container %q", container) } - img, err := ctr.Commit(c.BoolT("pause"), opts) + newImage, err := ctr.Commit(c.BoolT("pause"), reference, writer, image.SigningOptions{}, config) if err == nil { - fmt.Println(img.ID) + fmt.Println(newImage.ID()) } return nil } diff --git a/cmd/podman/create.go b/cmd/podman/create.go index efd7458ea..947f6d2a6 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -3,13 +3,6 @@ package main import ( "encoding/json" "fmt" - "io" - "net" - "os" - "strconv" - "strings" - "syscall" - "github.com/docker/docker/api/types/container" "github.com/docker/docker/pkg/signal" "github.com/docker/go-connections/nat" @@ -17,10 +10,16 @@ import ( "github.com/opencontainers/selinux/go-selinux/label" "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/libpod/image" "github.com/projectatomic/libpod/pkg/inspect" "github.com/projectatomic/libpod/pkg/util" "github.com/sirupsen/logrus" "github.com/urfave/cli" + "net" + "os" + "strconv" + "strings" + "syscall" ) type mountType string @@ -154,6 +153,7 @@ var createCommand = cli.Command{ func createCmd(c *cli.Context) error { // TODO should allow user to create based off a directory on the host not just image // Need CLI support for this + if err := validateFlags(c, createFlags); err != nil { return err } @@ -174,11 +174,14 @@ func createCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - imageName, _, data, err := imageData(c, runtime, c.Args()[0]) + rtc := runtime.GetConfig() + + newImage, err := runtime.ImageRuntime().New(c.Args()[0], rtc.SignaturePolicyPath, "", os.Stderr, nil, image.SigningOptions{}) if err != nil { return err } - createConfig, err := parseCreateOpts(c, runtime, imageName, data) + data, err := libpod.GetImageData(newImage) + createConfig, err := parseCreateOpts(c, runtime, newImage.Names()[0], data) if err != nil { return err } @@ -379,46 +382,6 @@ func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[na return portBindings, nil } -// imageData pulls down the image if not stored locally and extracts the -// default container runtime data out of it. imageData returns the data -// to the caller. Example Data: Entrypoint, Env, WorkingDir, Labels ... -func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, string, *inspect.ImageData, error) { - var ( - err error - imageName, imageID string - ) - // Deal with the image after all the args have been checked - createImage := runtime.NewImage(image) - imageName, imageID, _ = createImage.GetLocalImageName() - if createImage.LocalName == "" { - // The image wasnt found by the user input'd name or its fqname - // Pull the image - var writer io.Writer - if !c.Bool("quiet") { - writer = os.Stderr - } - createImage.Pull(writer) - } - - createImage.LocalName = imageName - if imageName == "" { - imageName, err = createImage.GetFQName() - _, imageID, _ = createImage.GetLocalImageName() - } - if err != nil { - return "", "", nil, err - } - storageImage, err := runtime.GetImage(imageName) - if err != nil { - return "", "", nil, errors.Wrapf(err, "error getting storage image %q", image) - } - data, err := runtime.GetImageInspectInfo(*storageImage) - if err != nil { - return "", "", nil, errors.Wrapf(err, "error parsing image data %q", image) - } - return imageName, imageID, data, err -} - // Parses CLI options related to container creation into a config which can be // parsed into an OCI runtime spec func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*createConfig, error) { diff --git a/cmd/podman/history.go b/cmd/podman/history.go index 1164555d3..0f9698f4f 100644 --- a/cmd/podman/history.go +++ b/cmd/podman/history.go @@ -98,8 +98,11 @@ func historyCmd(c *cli.Context) error { if len(args) > 1 { return errors.Errorf("podman history takes at most 1 argument") } - imgName := args[0] + image, err := runtime.ImageRuntime().NewFromLocal(args[0]) + if err != nil { + return err + } opts := historyOptions{ human: c.BoolT("human"), noTrunc: c.Bool("no-trunc"), @@ -107,12 +110,12 @@ func historyCmd(c *cli.Context) error { format: format, } - history, layers, imageID, err := runtime.GetHistory(imgName) + history, layers, err := image.History() if err != nil { - return errors.Wrapf(err, "error getting history of image %q", imgName) + return errors.Wrapf(err, "error getting history of image %q", image.InputName) } - return generateHistoryOutput(history, layers, imageID, opts) + return generateHistoryOutput(history, layers, image.ID(), opts) } func genHistoryFormat(format string, quiet bool) string { diff --git a/cmd/podman/import.go b/cmd/podman/import.go index d3c497d9d..6f7565b4b 100644 --- a/cmd/podman/import.go +++ b/cmd/podman/import.go @@ -11,7 +11,7 @@ import ( "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/libpod/image" "github.com/urfave/cli" ) @@ -55,8 +55,12 @@ func importCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - var opts libpod.CopyOptions - var source string + var ( + source string + reference string + writer io.Writer + ) + args := c.Args() switch len(args) { case 0: @@ -65,7 +69,7 @@ func importCmd(c *cli.Context) error { source = args[0] case 2: source = args[0] - opts.Reference = args[1] + reference = args[1] default: return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]") } @@ -87,11 +91,9 @@ func importCmd(c *cli.Context) error { History: history, } - opts.ImageConfig = config - opts.Writer = nil - + writer = nil if !c.Bool("quiet") { - opts.Writer = os.Stderr + writer = os.Stderr } // if source is a url, download it and save to a temp file @@ -105,9 +107,9 @@ func importCmd(c *cli.Context) error { source = file } - img, err := runtime.ImportImage(source, opts) + newImage, err := runtime.Import(source, reference, writer, image.SigningOptions{}, config) if err == nil { - fmt.Println(img.ID) + fmt.Println(newImage.ID()) } return err } diff --git a/cmd/podman/inspect.go b/cmd/podman/inspect.go index cfd257af4..b691b7a12 100644 --- a/cmd/podman/inspect.go +++ b/cmd/podman/inspect.go @@ -128,31 +128,27 @@ func iterateInput(c *cli.Context, args []string, runtime *libpod.Runtime, inspec break } case inspectTypeImage: - newImage := runtime.NewImage(input) - newImage.GetLocalImageName() - image, err := runtime.GetImage(newImage.LocalName) + image, err := runtime.ImageRuntime().NewFromLocal(input) if err != nil { inspectError = errors.Wrapf(err, "error getting image %q", input) break } - data, err = runtime.GetImageInspectInfo(*image) + data, err = libpod.GetImageData(image) if err != nil { - inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID) + inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID()) break } case inspectAll: ctr, err := runtime.LookupContainer(input) if err != nil { - newImage := runtime.NewImage(input) - newImage.GetLocalImageName() - image, err := runtime.GetImage(newImage.LocalName) + image, err := runtime.ImageRuntime().NewFromLocal(input) if err != nil { inspectError = errors.Wrapf(err, "error getting image %q", input) break } - data, err = runtime.GetImageInspectInfo(*image) + data, err = libpod.GetImageData(image) if err != nil { - inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID) + inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID()) break } } else { diff --git a/cmd/podman/rmi.go b/cmd/podman/rmi.go index f5938ffb9..b38686a87 100644 --- a/cmd/podman/rmi.go +++ b/cmd/podman/rmi.go @@ -6,6 +6,7 @@ import ( "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/libpod/image" "github.com/urfave/cli" ) @@ -51,28 +52,37 @@ func rmiCmd(c *cli.Context) error { return errors.Errorf("when using the --all switch, you may not pass any images names or IDs") } - imagesToDelete := args[:] + images := args[:] var lastError error + var imagesToDelete []*image.Image if removeAll { - localImages, err := runtime.GetImages(&libpod.ImageFilterParams{}) + imagesToDelete, err = runtime.GetImages(&libpod.ImageFilterParams{}) if err != nil { return errors.Wrapf(err, "unable to query local images") } - for _, image := range localImages { - imagesToDelete = append(imagesToDelete, image.ID) + } else { + // Create image.image objects for deletion from user input + for _, i := range images { + newImage, err := runtime.ImageRuntime().NewFromLocal(i) + if err != nil { + fmt.Fprintln(os.Stderr, err) + continue + } + imagesToDelete = append(imagesToDelete, newImage) } } - - for _, arg := range imagesToDelete { - image := runtime.NewImage(arg) - iid, err := image.Remove(c.Bool("force")) + if len(imagesToDelete) == 0 { + return errors.Errorf("no valid images to delete") + } + for _, img := range imagesToDelete { + err := runtime.RemoveImage(img, c.Bool("force")) if err != nil { if lastError != nil { fmt.Fprintln(os.Stderr, lastError) } lastError = err } else { - fmt.Println(iid) + fmt.Println(img.ID()) } } return lastError diff --git a/cmd/podman/run.go b/cmd/podman/run.go index 7b840a387..f1e11f839 100644 --- a/cmd/podman/run.go +++ b/cmd/podman/run.go @@ -7,8 +7,10 @@ import ( "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod" + "github.com/projectatomic/libpod/libpod/image" "github.com/sirupsen/logrus" "github.com/urfave/cli" + "os" ) var runDescription = "Runs a command in a new container from the given image" @@ -49,12 +51,15 @@ func runCmd(c *cli.Context) error { return errors.Errorf("image name or ID is required") } - imageName, _, data, err := imageData(c, runtime, c.Args()[0]) + rtc := runtime.GetConfig() + newImage, err := runtime.ImageRuntime().New(c.Args()[0], rtc.SignaturePolicyPath, "", os.Stderr, nil, image.SigningOptions{}) + + data, err := libpod.GetImageData(newImage) if err != nil { return err } - createConfig, err := parseCreateOpts(c, runtime, imageName, data) + createConfig, err := parseCreateOpts(c, runtime, newImage.Names()[0], data) if err != nil { return err } |