summaryrefslogtreecommitdiff
path: root/tcwg-cleanup-stale-containers.sh
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@linaro.org>2018-05-03 14:28:12 +0000
committerChristophe Lyon <christophe.lyon@linaro.org>2018-05-07 18:26:06 +0000
commit6fb10cfe68c26a491b907edc378b5b979b935b59 (patch)
tree0786b78d72efe324cb98477082ddd49e98982c0e /tcwg-cleanup-stale-containers.sh
parentb1da8656a1b458fd3333fa22670d5fd6f30e1595 (diff)
tcwg-cleanup-stale-containers.sh: Remove only containers started by Jenkins.
Implements TCWG-1404. Containers started by Jenkins jobs have names starting with a number, we want to cleanup only those. This behaviour is hardcoded by this patch, but controlled by a flag we can control later if needed. Change-Id: Idbf8eb6cfc44ccd7cdaad08019522f670046573e
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-xtcwg-cleanup-stale-containers.sh20
1 files changed, 19 insertions, 1 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh
index ff49529f..418823e0 100755
--- a/tcwg-cleanup-stale-containers.sh
+++ b/tcwg-cleanup-stale-containers.sh
@@ -54,6 +54,7 @@ do_cleanup_containers ()
local docker_ps_opts="$2"
local action="$3"
local cleanup_containers=true
+ local only_jenkins_containers=true
if [ "$hours" -lt "0" ]; then
hours="$((0-$hours))"
@@ -72,7 +73,22 @@ do_cleanup_containers ()
container_seconds=$((curdate-container_date))
if [ "$(($container_seconds/3600))" -gt "$hours" ]; then
- rm_containers=("${rm_containers[@]}" $container)
+
+ # Do we want to remove all containers, or only those
+ # started by Jenkins jobs?
+ if ${only_jenkins_containers}; then
+ container_name=$(DOCKER inspect --format "{{.Name}}")
+ # Containers started by our Jenkins jobs start with a
+ # number
+ case ${container_name} in
+ /[0-9]*)
+ ;;
+ *)
+ container=""
+ ;;
+ esac
+ fi
+ rm_containers=("${rm_containers[@]}" $container)
fi
done
@@ -98,6 +114,8 @@ do_cleanup_containers ()
echo "Containers report after:"
$DOCKER ps $docker_ps_opts
+ else
+ echo "Found no container to remove"
fi
exit $status