X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=jjb%2Fdovetail%2Fdovetail-cleanup.sh;h=0ee789a97e690a9e8350d2ac9670508c2292a7f0;hb=6a80a19f991a9ba91190187554fec105e9c79ae1;hp=f215278db383ee2b516afbb6a66b2008d192e4a0;hpb=d8ec3fcab553c186736224caa1a1f187dff7bdc5;p=releng.git diff --git a/jjb/dovetail/dovetail-cleanup.sh b/jjb/dovetail/dovetail-cleanup.sh index f215278db..0ee789a97 100755 --- a/jjb/dovetail/dovetail-cleanup.sh +++ b/jjb/dovetail/dovetail-cleanup.sh @@ -2,14 +2,35 @@ [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null" -echo "Cleaning up docker containers/images..." -# Remove previous running containers if exist +# clean up dependent project docker images, which has no containers and image tag None +clean_images=(opnfv/functest opnfv/yardstick opnfv/testapi mongo) +for clean_image in "${clean_images[@]}"; do + echo "Removing image $image_id, which has no containers and image tag is None" + dangling_images=($(docker images -f "dangling=true" | grep ${clean_image} | awk '{print $3}')) + if [[ -n ${dangling_images} ]]; then + for image_id in "${dangling_images[@]}"; do + docker rmi $image_id >${redirect} + done + fi +done + +echo "Remove containers with image opnfv/dovetail:..." +dangling_images=($(docker images -f "dangling=true" | grep opnfv/dovetail | awk '{print $3}')) +if [[ -n ${dangling_images} ]]; then + for image_id in "${dangling_images[@]}"; do + echo "Removing image $image_id with tag None and its related containers" + docker ps -a | grep $image_id | awk '{print $1}'| xargs docker rm -f >${redirect} + docker rmi $image_id >${redirect} + done +fi + +echo "Cleaning up dovetail docker containers..." if [[ ! -z $(docker ps -a | grep opnfv/dovetail) ]]; then echo "Removing existing opnfv/dovetail containers..." docker ps -a | grep opnfv/dovetail | awk '{print $1}' | xargs docker rm -f >${redirect} fi -# Remove existing images if exist +echo "Remove dovetail existing images if exist..." if [[ ! -z $(docker images | grep opnfv/dovetail) ]]; then echo "Docker images to remove:" docker images | head -1 && docker images | grep opnfv/dovetail >${redirect}