Resolve build silent failure 25/28225/5
authorZhijiang Hu <hu.zhijiang@zte.com.cn>
Tue, 7 Feb 2017 12:53:08 +0000 (07:53 -0500)
committerZhijiang Hu <hu.zhijiang@zte.com.cn>
Tue, 7 Feb 2017 13:18:56 +0000 (08:18 -0500)
1) Add "-f" to docker rmi command, otherwise we encountered "Error
response from daemon: conflict: unable to remove repository ..."

2) Remove "2>&1" to get error message printed out if present.

3) Add cleanup_container, otherwise we got "Error response from
daemon: Conflict. The name "/daisy" is already in use by container"

Change-Id: Ic5cecb34699c6fbe0d3af45be38633d35bdfc89f
Signed-off-by: Zhijiang Hu <hu.zhijiang@zte.com.cn>
ci/build_rpm/build_rpms.sh

index c98747b..811eb13 100755 (executable)
@@ -25,11 +25,34 @@ function build_rpm_pkg {
                     $OPNFV_ARTIFACT_VERSION
 }
 
+function cleanup_container {
+    echo "Cleaning daisy container"
+    containers_to_kill=$(sudo docker ps --filter "name=daisy" \
+        --format "{{.Names}}" -a)
+
+    if [[ ! -z "$containers_to_kill" ]]; then
+        volumes_to_remove=$(sudo docker inspect -f \
+            '{{range .Mounts}} {{printf "%s\n" .Name }}{{end}}' \
+            ${containers_to_kill} | egrep -v '(^\s*$)' | sort | uniq)
+
+        echo "Stopping containers... $containers_to_kill"
+        (sudo docker stop -t 2 ${containers_to_kill} 2>&1) > /dev/null
+        echo "Removing containers... $containers_to_kill"
+        (sudo docker rm -v -f ${containers_to_kill} 2>&1) > /dev/null
+
+        if [[ ! -z "$containers_to_kill" ]]; then
+            echo "Removing volumes... $volumes_to_remove"
+            (sudo docker volume rm ${volumes_to_remove} 2>&1) || true > /dev/null
+        fi
+    fi
+}
+
 function cleanup_docker_image {
     if [ ! -z "$(sudo docker images -q opnfv/daisy)" ]; then
-        sudo docker rmi opnfv/daisy >/dev/null 2>&1
+        sudo docker rmi -f opnfv/daisy
     fi
 }
 
+cleanup_container
 cleanup_docker_image
 build_rpm_pkg