summaryrefslogtreecommitdiffstats
path: root/jjb/functest/functest-cleanup.sh
diff options
context:
space:
mode:
authorhelenyao <yaohelan@huawei.com>2016-12-18 21:48:21 -0500
committerhelenyao <yaohelan@huawei.com>2016-12-21 04:17:26 -0500
commit045f7483a90be49493e11be06c3fb8efac19e37d (patch)
tree26e1bbfa3ef72c79bc945f85bcf17298fd742008 /jjb/functest/functest-cleanup.sh
parentd78d0e1e358d294f5af61e4e800eeac67c23e56a (diff)
opnfv/functest:<none> and its containers are removed
JIRA: FUNCTEST-653 opnfv/functest images with <none> tag are generated after functest images are pull many times. These images can be queried with filter "dangling". Logics are added to remove dangling images and their containers. Change-Id: I271f4d95c5fb62fdebe690d82330f6b25ac1e2f8 Signed-off-by: helenyao <yaohelan@huawei.com>
Diffstat (limited to 'jjb/functest/functest-cleanup.sh')
-rwxr-xr-xjjb/functest/functest-cleanup.sh37
1 files changed, 26 insertions, 11 deletions
diff --git a/jjb/functest/functest-cleanup.sh b/jjb/functest/functest-cleanup.sh
index a1ae67d99..f8140e058 100755
--- a/jjb/functest/functest-cleanup.sh
+++ b/jjb/functest/functest-cleanup.sh
@@ -3,19 +3,34 @@
[[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
echo "Cleaning up docker containers/images..."
+FUNCTEST_IMAGE=opnfv/functest
+# Remove containers along with image opnfv/functest:<none>
+dangling_images=($(docker images -f "dangling=true" | grep $FUNCTEST_IMAGE | awk '{print $1}'))
+if [[ -n ${dangling_images} ]]; then
+ echo " Removing $FUNCTEST_IMAGE:<none> images and their containers..."
+ for image_id in "${dangling_images[@]}"; do
+ echo " Removing image_id: $image_id and its containers"
+ docker ps -a | grep $image_id | awk '{print $1}'| xargs docker rm -f >${redirect}
+ docker rmi $image_id >${redirect}
+ done
+fi
+
# Remove previous running containers if exist
-if [[ ! -z $(docker ps -a | grep opnfv/functest) ]]; then
- echo "Removing existing opnfv/functest containers..."
- docker ps -a | grep opnfv/functest | awk '{print $1}' | xargs docker rm -f >${redirect}
+functest_containers=$(docker ps -a | grep $FUNCTEST_IMAGE | awk '{print $1}')
+if [[ -n ${functest_containers} ]]; then
+ echo " Removing existing $FUNCTEST_IMAGE containers..."
+ docker rm -f $functest_containers >${redirect}
fi
# Remove existing images if exist
-if [[ $CLEAN_DOCKER_IMAGES == true ]] && [[ ! -z $(docker images | grep opnfv/functest) ]]; then
- echo "Docker images to remove:"
- docker images | head -1 && docker images | grep opnfv/functest >${redirect}
- image_tags=($(docker images | grep opnfv/functest | awk '{print $2}'))
- for tag in "${image_tags[@]}"; do
- echo "Removing docker image opnfv/functest:$tag..."
- docker rmi opnfv/functest:$tag >/dev/null
- done
+if [[ $CLEAN_DOCKER_IMAGES == true ]]; then
+ functest_image_tags=($(docker images | grep $FUNCTEST_IMAGE | awk '{print $2}'))
+ if [[ -n ${functest_image_tags} ]]; then
+ echo " Docker images to be removed:" >${redirect}
+ (docker images | head -1 && docker images | grep $FUNCTEST_IMAGE) >${redirect}
+ for tag in "${functest_image_tags[@]}"; do
+ echo " Removing docker image $FUNCTEST_IMAGE:$tag..."
+ docker rmi $FUNCTEST_IMAGE:$tag >${redirect}
+ done
+ fi
fi