2 # Licensed to the Apache Software Foundation (ASF) under one *
3 # or more contributor license agreements. See the NOTICE file *
4 # distributed with this work for additional information *
5 # regarding copyright ownership. The ASF licenses this file *
6 # to you under the Apache License, Version 2.0 (the *
7 # "License"); you may not use this file except in compliance *
8 # with the License. You may obtain a copy of the License at *
10 # http://www.apache.org/licenses/LICENSE-2.0 *
12 # Unless required by applicable law or agreed to in writing, *
13 # software distributed under the License is distributed on an *
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 # KIND, either express or implied. See the License for the *
16 # specific language governing permissions and limitations *
17 # under the License. *
27 cmd=`curl -s --head --request GET ${url} | grep '200 OK' > /dev/null`
40 echo "Getting contianer Id of the currently running one"
41 contId=$(sudo docker ps | grep "opnfv/testapi:latest" | awk '{print $1}')
43 echo "Pulling the latest image"
44 sudo docker pull opnfv/testapi:latest
46 echo "Deleting old containers of opnfv/testapi:old"
47 sudo docker ps -a | grep "opnfv/testapi" | grep "old" | awk '{print $1}' | xargs -r sudo docker rm -f
49 echo "Deleting old images of opnfv/testapi:latest"
50 sudo docker images | grep "opnfv/testapi" | grep "old" | awk '{print $3}' | xargs -r sudo docker rmi -f
55 echo "No running testapi container"
57 echo "Removing stopped testapi containers in the previous iterations"
58 sudo docker ps -f status=exited | grep "opnfv_testapi" | awk '{print $1}' | xargs -r sudo docker rm -f
62 echo "Get the image id of the currently running conatiner"
63 currImgId=$(sudo docker ps | grep "$contId" | awk '{print $2}')
66 if [[ -z "$currImgId" ]]
68 echo "No image id found for the container id"
72 echo "Changing current image tag to old"
73 sudo docker tag "$currImgId" opnfv/testapi:old
75 echo "Removing stopped testapi containers in the previous iteration"
76 sudo docker ps -f status=exited | grep "opnfv_testapi" | awk '{print $1}' | xargs -r sudo docker rm -f
78 echo "Renaming the running container name to opnfv_testapi as to identify it."
79 sudo docker rename $contId opnfv_testapi
81 echo "Stop the currently running container"
82 sudo docker stop $contId
85 echo "Running a container with the new image"
89 echo "TestResults Hosted."
91 echo "TestResults Hosting Failed"
92 if [[ $(sudo docker images | grep "opnfv/testapi" | grep "old" | awk '{print $3}') ]]; then
93 echo "Running old Image"
99 # Echo Images and Containers