diff options
| author | Martin Hiner <m.hiner@partner.samsung.com> | 2022-11-21 18:38:57 +0100 |
|---|---|---|
| committer | Martin Hiner <m.hiner@partner.samsung.com> | 2023-04-28 16:16:55 +0200 |
| commit | 53e8b80ed36a9193627862427fa224ed38375d3a (patch) | |
| tree | 14463dda4a87452345c37a1a5252d50db057bc12 /tools/cleanup-images | |
| parent | 92ddbdfbc190ec430f5527fcf867efec97e455b4 (diff) | |
| download | kolla-ansible-53e8b80ed36a9193627862427fa224ed38375d3a.tar.gz kolla-ansible-53e8b80ed36a9193627862427fa224ed38375d3a.zip | |
Add container engine option to scripts
This patch add a way to choose container engine inside tool and test
scripts. This is in preparation for Podman introduction but still
leaves Docker as default container engine.
Signed-off-by: Martin Hiner <m.hiner@partner.samsung.com>
Change-Id: I395d2bdb0dfb4b325b6ad197c8893c8a0f768324
Diffstat (limited to 'tools/cleanup-images')
| -rwxr-xr-x | tools/cleanup-images | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/tools/cleanup-images b/tools/cleanup-images index 87b2084ac..3d08883c7 100755 --- a/tools/cleanup-images +++ b/tools/cleanup-images @@ -1,7 +1,9 @@ #!/usr/bin/env bash +container_engine="docker" + # Move to top level directory -REAL_PATH=$(python -c "import os;print os.path.realpath('$0')") +REAL_PATH=$(python3 -c "import os;print(os.path.realpath('$0'))") cd "$(dirname "$REAL_PATH")/.." function process_cmd { @@ -28,34 +30,50 @@ Options: --help, -h Show this usage information --image, -i <image> Delete selected images --image-version <image_version> Set Kolla image version + --engine, -e <container_engine> Container engine to be used EOF } -SHORT_OPTS="ahi:" -LONG_OPTS="all,dangling,help,image:,image-version:" +SHORT_OPTS="ahi:e:" +LONG_OPTS="all,dangling,help,image:,image-version:,engine:" ARGS=$(getopt -o "${SHORT_OPTS}" -l "${LONG_OPTS}" --name "$0" -- "$@") || { usage >&2; exit 2; } -eval set -- "$ARGS" + +for arg do + shift + if [ "$arg" = "-e" ] || [ "$arg" = "--engine" ]; then + container_engine="$1" + continue + elif [ "$arg" = "$container_engine" ]; then + continue + fi + eval set -- "$@" "$arg" +done + +# catch empty arguments +if [ "$ARGS" = " --" ]; then + eval set -- "$ARGS" +fi case "$1" in (--all|-a) - KOLLA_IMAGES="$(sudo docker images -a --filter "label=kolla_version" --format "{{.ID}}")" + KOLLA_IMAGES="$(sudo ${container_engine} images -a --filter "label=kolla_version" --format "{{.ID}}")" shift ;; (--dangling) - KOLLA_IMAGES="$(sudo docker images -a --filter dangling=true --format "{{.ID}}")" + KOLLA_IMAGES="$(sudo ${container_engine} images -a --filter dangling=true --format "{{.ID}}")" shift ;; (--image|-i) - KOLLA_IMAGES="$(sudo docker images -a --filter "label=kolla_version" --format "{{.Repository}}\t{{.ID}}" | grep -E "$2" | awk '{print $2}')" + KOLLA_IMAGES="$(sudo ${container_engine} images -a --filter "label=kolla_version" --format "{{.Repository}}\t{{.ID}}" | grep -E "$2" | awk '{print $2}')" shift 2 ;; (--image-version) - KOLLA_IMAGES="$(sudo docker images -a --filter "label=kolla_version=${2}" --format "{{.ID}}")" + KOLLA_IMAGES="$(sudo ${container_engine} images -a --filter "label=kolla_version=${2}" --format "{{.ID}}")" shift 2 ;; @@ -73,5 +91,5 @@ case "$1" in esac -CMD="sudo docker rmi -f $@ $KOLLA_IMAGES" +CMD="sudo ${container_engine} rmi -f $@ -- $KOLLA_IMAGES" process_cmd |
