Disable blocking on buildable queue (Functest)
[releng.git] / jjb / dovetail / dovetail-cleanup.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
11
12 # clean up dependent project docker images, which has no containers and image tag None
13 clean_images=(opnfv/functest opnfv/yardstick opnfv/testapi mongo)
14 for clean_image in "${clean_images[@]}"; do
15     dangling_images=($(docker images -f "dangling=true" | grep ${clean_image} | awk '{print $3}'))
16     if [[ -n ${dangling_images} ]]; then
17         for image_id in "${dangling_images[@]}"; do
18             echo "Removing image $image_id, which has no containers and image tag is None"
19             docker rmi $image_id >${redirect}
20         done
21     fi
22 done
23
24 echo "Remove dovetail images with tag None and containers with these images ..."
25 dangling_images=($(docker images -f "dangling=true" | grep opnfv/dovetail | awk '{print $3}'))
26 if [[ -n ${dangling_images} ]]; then
27     for image_id in "${dangling_images[@]}"; do
28         echo "Removing image $image_id with tag None and its related containers"
29         docker ps -a | grep $image_id | awk '{print $1}'| xargs docker rm -f >${redirect}
30         docker rmi $image_id >${redirect}
31     done
32 fi
33
34 echo "Cleaning up dovetail docker containers..."
35 if [[ ! -z $(docker ps -a | grep opnfv/dovetail) ]]; then
36     echo "Removing existing opnfv/dovetail containers..."
37     docker ps -a | grep opnfv/dovetail | awk '{print $1}' | xargs docker rm -f >${redirect}
38 fi
39
40 #echo "Remove dovetail existing images if exist..."
41 #if [[ ! -z $(docker images | grep opnfv/dovetail) ]]; then
42 #    echo "Docker images to remove:"
43 #    docker images | head -1 && docker images | grep opnfv/dovetail >${redirect}
44 #    image_tags=($(docker images | grep opnfv/dovetail | awk '{print $2}'))
45 #    for tag in "${image_tags[@]}"; do
46 #        echo "Removing docker image opnfv/dovetail:$tag..."
47 #        docker rmi opnfv/dovetail:$tag >${redirect}
48 #    done
49 #fi