7 cmd=`curl -s --head --request GET http://testresults.opnfv.org/test/swagger/spec | grep '200 OK' > /dev/null`
20 echo "Getting contianer Id of the currently running one"
21 contId=$(sudo docker ps | grep "opnfv/testapi:latest" | awk '{print $1}')
23 echo "Pulling the latest image"
24 sudo docker pull opnfv/testapi:latest
26 echo "Deleting old containers of opnfv/testapi:old"
27 sudo docker ps -a | grep "opnfv/testapi" | grep "old" | awk '{print $1}' | xargs -r sudo docker rm -f
29 echo "Deleting old images of opnfv/testapi:latest"
30 sudo docker images | grep "opnfv/testapi" | grep "old" | awk '{print $3}' | xargs -r sudo docker rmi -f
35 echo "No running testapi container"
37 echo "Removing stopped testapi containers in the previous iterations"
38 sudo docker ps -f status=exited | grep "opnfv_testapi" | awk '{print $1}' | xargs -r sudo docker rm -f
42 echo "Get the image id of the currently running conatiner"
43 currImgId=$(sudo docker ps | grep "$contId" | awk '{print $2}')
46 if [[ -z "$currImgId" ]]
48 echo "No image id found for the container id"
52 echo "Changing current image tag to old"
53 sudo docker tag "$currImgId" opnfv/testapi:old
55 echo "Removing stopped testapi containers in the previous iteration"
56 sudo docker ps -f status=exited | grep "opnfv_testapi" | awk '{print $1}' | xargs -r sudo docker rm -f
58 echo "Renaming the running container name to opnfv_testapi as to identify it."
59 sudo docker rename $contId opnfv_testapi
61 echo "Stop the currently running container"
62 sudo docker stop $contId
65 echo "Running a container with the new image"
66 sudo docker run -dti -p "8082:8000" -e "mongodb_url=mongodb://172.17.0.1:27017" -e "swagger_url=http://testresults.opnfv.org/test" opnfv/testapi:latest
69 echo "TestResults Hosted."
71 echo "TestResults Hosting Failed"
72 if [[ $(sudo docker images | grep "opnfv/testapi" | grep "old" | awk '{print $3}') ]]; then
73 echo "Running old Image"
74 sudo docker run -dti -p "8082:8000" -e "mongodb_url=mongodb://172.17.0.1:27017" -e "swagger_url=http://testresults.opnfv.org/test" opnfv/testapi:old
79 # Echo Images and Containers