3 [[ $CI_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null"
5 echo "Cleaning up docker containers/images..."
6 FUNCTEST_IMAGE=opnfv/functest
8 # Remove containers along with image opnfv/functest*:<none>
9 dangling_images=($(docker images -f "dangling=true" | grep $FUNCTEST_IMAGE | awk '{print $3}'))
10 if [[ -n ${dangling_images} ]]; then
11 echo " Removing $FUNCTEST_IMAGE:<none> images and their containers..."
12 for image_id in "${dangling_images[@]}"; do
13 echo " Removing image_id: $image_id and its containers"
14 containers=$(docker ps -a | grep $image_id | awk '{print $1}')
15 if [[ -n "$containers" ]];then
16 docker rm -f $containers >${redirect}
18 docker rmi $image_id >${redirect}
22 # Remove previous running containers if exist
23 functest_containers=$(docker ps -a | grep $FUNCTEST_IMAGE | awk '{print $1}')
24 if [[ -n ${functest_containers} ]]; then
25 echo " Removing existing $FUNCTEST_IMAGE containers..."
26 docker rm -f $functest_containers >${redirect}
29 # Remove existing images if exist
30 if [[ $CLEAN_DOCKER_IMAGES == true ]]; then
31 functest_image_tags=($(docker images | grep $FUNCTEST_IMAGE | awk '{print $2}'))
32 if [[ -n ${functest_image_tags} ]]; then
33 echo " Docker images to be removed:" >${redirect}
34 (docker images | head -1 && docker images | grep $FUNCTEST_IMAGE) >${redirect}
35 for tag in "${functest_image_tags[@]}"; do
36 echo " Removing docker image $FUNCTEST_IMAGE:$tag..."
37 docker rmi $FUNCTEST_IMAGE:$tag >${redirect}