diff options
author | umohnani8 <umohnani@redhat.com> | 2018-06-14 14:53:59 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-06-18 14:41:51 +0000 |
commit | db094f6e15d3e63772d4346b0176cb6fc682b2fc (patch) | |
tree | a48a5eff164c91be48919e436eb3a3f9c58b96b8 /cmd/podman | |
parent | 4d3db1b4a9ec1a1a2aa74e3da0102b6017f8a328 (diff) | |
download | podman-db094f6e15d3e63772d4346b0176cb6fc682b2fc.tar.gz podman-db094f6e15d3e63772d4346b0176cb6fc682b2fc.tar.bz2 podman-db094f6e15d3e63772d4346b0176cb6fc682b2fc.zip |
Add --all,-a flag to podman images
podman images will not show intermediate images by default.
To view all images, including intermediate images created during
a build, use the --all flag.
Signed-off-by: umohnani8 <umohnani@redhat.com>
Closes: #947
Approved by: rhatdan
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/images.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/cmd/podman/images.go b/cmd/podman/images.go index 7b906178d..654e59845 100644 --- a/cmd/podman/images.go +++ b/cmd/podman/images.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/containers/storage" "github.com/docker/go-units" digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" @@ -43,6 +44,7 @@ type imagesOptions struct { format string outputformat string sort string + all bool } // Type declaration and functions for sorting the images output @@ -178,6 +180,7 @@ func imagesCmd(c *cli.Context) error { digests: c.Bool("digests"), format: c.String("format"), sort: c.String("sort"), + all: c.Bool("all"), } opts.outputformat = opts.setOutputFormat() @@ -256,8 +259,14 @@ func sortImagesOutput(sortBy string, imagesOutput imagesSorted) imagesSorted { } // getImagesTemplateOutput returns the images information to be printed in human readable format -func getImagesTemplateOutput(ctx context.Context, runtime *libpod.Runtime, images []*image.Image, opts imagesOptions) (imagesOutput imagesSorted) { +func getImagesTemplateOutput(ctx context.Context, runtime *libpod.Runtime, images []*image.Image, opts imagesOptions, storageLayers []storage.Layer) (imagesOutput imagesSorted) { for _, img := range images { + // If all is false and the image doesn't have a name, check to see if the top layer of the image is a parent + // to another image's top layer. If it is, then it is an intermediate image so don't print out if the --all flag + // is not set. + if !opts.all && len(img.Names()) == 0 && !layerIsLeaf(storageLayers, img.TopLayer()) { + continue + } createdTime := img.Created() imageID := "sha256:" + img.ID() @@ -316,13 +325,17 @@ func generateImagesOutput(ctx context.Context, runtime *libpod.Runtime, images [ return nil } var out formats.Writer + storageLayers, err := runtime.GetLayers() + if err != nil { + return errors.Wrap(err, "error getting layers from store") + } switch opts.format { case formats.JSONString: imagesOutput := getImagesJSONOutput(ctx, runtime, images) out = formats.JSONStructArray{Output: imagesToGeneric([]imagesTemplateParams{}, imagesOutput)} default: - imagesOutput := getImagesTemplateOutput(ctx, runtime, images, opts) + imagesOutput := getImagesTemplateOutput(ctx, runtime, images, opts, storageLayers) out = formats.StdoutTemplateArray{Output: imagesToGeneric(imagesOutput, []imagesJSONParams{}), Template: opts.outputformat, Fields: imagesOutput[0].HeaderMap()} } return formats.Writer(out).Out() @@ -378,3 +391,14 @@ func CreateFilterFuncs(ctx context.Context, r *libpod.Runtime, c *cli.Context, i } return filterFuncs, nil } + +// layerIsLeaf goes through the layers in the store and checks if "layer" is +// the parent of any other layer in store. +func layerIsLeaf(storageLayers []storage.Layer, layer string) bool { + for _, storeLayer := range storageLayers { + if storeLayer.Parent == layer { + return false + } + } + return true +} |