summaryrefslogtreecommitdiff
path: root/tcwg-cleanup-stale-containers.sh
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2017-04-12 10:09:11 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2017-04-12 10:09:11 +0000
commit08fc0cceeade1f5f20f9211e0ea9745656641fb5 (patch)
tree7d4d768fdab74b4c6d55fca4582fd4e1888b677c /tcwg-cleanup-stale-containers.sh
parent3fa23da28ad73d0fe4b512c4aab269b5280a6650 (diff)
tcwg-cleanup-stale-containers: Allow partial cleanups
In our current workflow we should not generate stale volumes or containers, but we can generate stale images. Add options to allow cleaning up what we need, instead of all or nothing. Change-Id: Id270a7e51f4c931c32a08d2f244e727a7d783750
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-xtcwg-cleanup-stale-containers.sh16
1 files changed, 10 insertions, 6 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh
index d69c8c1d..b05f220b 100755
--- a/tcwg-cleanup-stale-containers.sh
+++ b/tcwg-cleanup-stale-containers.sh
@@ -3,15 +3,19 @@
set -e
docker_ps_opts=""
-dry_run=false
hours="10"
verbose=false
+clean_containers=false
+clean_volumes=false
+clean_images=false
-OPTS="`getopt -l docker_ps_opts:,dry_run:,hours:,verbose: -- "$@"`"
+OPTS="`getopt -l clean-containers:,clean-images:,clean-volumes:,docker_ps_opts:,hours:,verbose: -- "$@"`"
while test $# -gt 1; do
case $1 in
+ --clean-containters) clean_containers="$2"; shift ;;
+ --clean-images) clean_images="$2"; shift ;;
+ --clean-volumes) clean_volumes="$2"; shift ;;
--docker_ps_opts) docker_ps_opts="$2"; shift ;;
- --dry_run) dry_run="$2"; shift ;;
--hours) hours="$2"; shift ;;
--verbose) verbose="$2"; shift ;;
esac
@@ -49,7 +53,7 @@ if [ ${#rm_containers[@]} != 0 ]; then
echo "Removing containers: ${rm_containers[@]}"
echo "Increasing exit code by 1 to indicate stale containers"
status="$(($status+1))"
- if ! $dry_run; then
+ if $clean_containers; then
for container in "${rm_containers[@]}"; do
echo "Removing container $container"
docker rm -f -v $container | cat
@@ -67,7 +71,7 @@ if [ x"$(docker volume ls -q -f dangling=true)" != x"" ]; then
echo "Removing dangling volumes"
echo "Increasing exit code by 2 to indicate dangling volumes"
status="$(($status+2))"
- if ! $dry_run; then
+ if $clean_volumes; then
docker volume ls -q -f dangling=true | xargs docker volume rm | cat
echo "xargs docker volume rm exit status: ${PIPESTATUS[1]}"
else
@@ -86,7 +90,7 @@ if [ ${#rm_images[@]} != 0 ]; then
echo "Removing unused images"
echo "Increasing exit code by 4 to indicate unused images"
status="$(($status+4))"
- if ! $dry_run; then
+ if $clean_images; then
for image in "${rm_images[@]}"; do
docker rmi $image | cat
echo "docker rmi exit status: ${PIPESTATUS[0]}"