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