Disable blocking on buildable queue (Functest)
[releng.git] / jjb / yardstick / yardstick-cleanup.sh
1 #!/bin/bash
2 [[ ${CI_DEBUG} == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
3
4 # Remove containers along with image opnfv/yardstick*:<none>
5 dangling_images=($(docker images -f "dangling=true" | awk '/opnfv[/]yardstick/ {print $3}'))
6 if [[ ${#dangling_images[@]} -eq 0 ]] ; then
7     echo "Removing opnfv/yardstick:<none> images and their containers..."
8     for image_id in "${dangling_images[@]}"; do
9         echo "      Removing image_id: $image_id and its containers"
10         containers=$(docker ps -a | awk "/${image_id}/ {print \$1}")
11         if [[ -n "$containers" ]];then
12             docker rm -f "${containers}" >${redirect}
13         fi
14         docker rmi "${image_id}" >${redirect}
15     done
16 fi
17
18 echo "Cleaning up docker containers/images..."
19 # Remove previous running containers if exist
20 if docker ps -a | grep -q opnfv/yardstick; then
21     echo "Removing existing opnfv/yardstick containers..."
22     docker ps -a | awk "/${image_id}/ {print \$1}" | xargs docker rm -f >${redirect}
23
24 fi
25
26 # Remove existing images if exist
27 if docker images | grep -q opnfv/yardstick; then
28     echo "Docker images to remove:"
29     docker images | head -1 && docker images | grep opnfv/yardstick
30     image_ids=($(docker images | awk '/opnfv[/]yardstick/ {print $3}'))
31     for id in "${image_ids[@]}"; do
32         echo "Removing docker image id $id..."
33         docker rmi "${id}" >${redirect}
34     done
35 fi
36