summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2017-11-13 16:16:47 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-14 16:46:26 +0000
commit7df322123290ee600812312421b98cfb97031e9f (patch)
tree2aa3651fb88c62185706f221c385a98fd749f25b
parent55c9cfb80e066713f009547f7df7dddd2da35eb8 (diff)
downloadpodman-7df322123290ee600812312421b98cfb97031e9f.tar.gz
podman-7df322123290ee600812312421b98cfb97031e9f.tar.bz2
podman-7df322123290ee600812312421b98cfb97031e9f.zip
Remove all images
Add -a/--all to rmi so a user can remove all images quickly. Signed-off-by: baude <bbaude@redhat.com> Closes: #41 Approved by: mheon
-rw-r--r--cmd/kpod/rmi.go24
-rw-r--r--completions/bash/kpod2
-rw-r--r--docs/kpod-rmi.1.md5
-rw-r--r--test/kpod_rmi.bats52
4 files changed, 80 insertions, 3 deletions
diff --git a/cmd/kpod/rmi.go b/cmd/kpod/rmi.go
index 3713db454..b69b3b514 100644
--- a/cmd/kpod/rmi.go
+++ b/cmd/kpod/rmi.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/pkg/errors"
+ "github.com/projectatomic/libpod/libpod"
"github.com/urfave/cli"
)
@@ -11,6 +12,10 @@ var (
rmiDescription = "removes one or more locally stored images."
rmiFlags = []cli.Flag{
cli.BoolFlag{
+ Name: "all, a",
+ Usage: "remove all images",
+ },
+ cli.BoolFlag{
Name: "force, f",
Usage: "force removal of the image",
},
@@ -29,7 +34,7 @@ func rmiCmd(c *cli.Context) error {
if err := validateFlags(c, rmiFlags); err != nil {
return err
}
-
+ removeAll := c.Bool("all")
runtime, err := getRuntime(c)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
@@ -37,11 +42,24 @@ func rmiCmd(c *cli.Context) error {
defer runtime.Shutdown(false)
args := c.Args()
- if len(args) == 0 {
+ if len(args) == 0 && !removeAll {
return errors.Errorf("image name or ID must be specified")
}
+ if len(args) > 0 && removeAll {
+ return errors.Errorf("when using the --all switch, you may not pass any images names or IDs")
+ }
+ imagesToDelete := args[:]
+ if removeAll {
+ localImages, 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)
+ }
+ }
- for _, arg := range args {
+ for _, arg := range imagesToDelete {
image, err := runtime.GetImage(arg)
if err != nil {
return errors.Wrapf(err, "could not get image %q", arg)
diff --git a/completions/bash/kpod b/completions/bash/kpod
index c13e64379..34cf86526 100644
--- a/completions/bash/kpod
+++ b/completions/bash/kpod
@@ -1238,6 +1238,8 @@ _kpod_rmi() {
-h
--force
-f
+ -a
+ --all
"
case "$cur" in
diff --git a/docs/kpod-rmi.1.md b/docs/kpod-rmi.1.md
index 1566f9612..2674c7ac2 100644
--- a/docs/kpod-rmi.1.md
+++ b/docs/kpod-rmi.1.md
@@ -13,6 +13,9 @@ Removes one or more locally stored images.
## OPTIONS
+**-all**, **-a**
+
+Remove all of the locally storage images
**--force, -f**
Executing this command will stop all containers that are using the image and remove them from the system
@@ -25,6 +28,8 @@ kpod rmi --force imageID
kpod rmi imageID1 imageID2 imageID3
+kpod rmi -a -f
+
## SEE ALSO
kpod(1)
diff --git a/test/kpod_rmi.bats b/test/kpod_rmi.bats
new file mode 100644
index 000000000..77990d500
--- /dev/null
+++ b/test/kpod_rmi.bats
@@ -0,0 +1,52 @@
+#!/usr/bin/env bats
+
+load helpers
+
+IMAGE1="docker.io/library/alpine:latest"
+IMAGE2="docker.io/library/busybox:latest"
+IMAGE3="docker.io/library/busybox:glibc"
+
+function teardown() {
+ cleanup_test
+}
+
+function pullImages() {
+ ${KPOD_BINARY} $KPOD_OPTIONS pull $IMAGE1
+ ${KPOD_BINARY} $KPOD_OPTIONS pull $IMAGE2
+ ${KPOD_BINARY} $KPOD_OPTIONS pull $IMAGE3
+}
+
+@test "kpod rmi bogus image" {
+ run ${KPOD_BINARY} $KPOD_OPTIONS rmi debian:6.0.10
+ echo "$output"
+ [ "$status" -eq 1 ]
+}
+
+@test "kpod rmi image with fq name" {
+ pullImages
+ run ${KPOD_BINARY} $KPOD_OPTIONS rmi $IMAGE1
+ echo "$output"
+ [ "$status" -eq 0 ]
+}
+
+@test "kpod rmi image with short name" {
+ pullImages
+ run ${KPOD_BINARY} $KPOD_OPTIONS rmi alpine
+ echo "$output"
+ [ "$status" -eq 0 ]
+}
+
+@test "kpod rmi all images" {
+ pullImages
+ run ${KPOD_BINARY} $KPOD_OPTIONS rmi -a
+ echo "$output"
+ [ "$status" -eq 0 ]
+}
+
+@test "kpod rmi all images forceably" {
+ pullImages
+ ${KPOD_BINARY} $KPOD_OPTIONS create ${IMAGE1} ls
+ run ${KPOD_BINARY} $KPOD_OPTIONS rmi -a -f
+ echo "$output"
+ [ "$status" -eq 0 ]
+}