From 2c28d74c6f4d00737362a441d2ebd5fa2cc7c02f Mon Sep 17 00:00:00 2001 From: Sakala Venkata Krishna Rohit Date: Sat, 8 Jul 2017 12:23:03 +0530 Subject: [PATCH] Making docker deploy script generic Replacing words with variables to make docker deploy generic so that it can be availed by other modules. Change-Id: Iacf4829aa5feede48038b71155a4dab43a8d427d Signed-off-by: Sakala Venkata Krishna Rohit --- jjb/releng/automate.yml | 9 +++++++-- jjb/releng/docker-deploy.sh | 37 ++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/jjb/releng/automate.yml b/jjb/releng/automate.yml index 17b6fa7c8..e81000afa 100644 --- a/jjb/releng/automate.yml +++ b/jjb/releng/automate.yml @@ -249,12 +249,17 @@ name: 'testapi-automate-docker-deploy-macro' builders: - shell: | - bash ./jjb/releng/docker-deploy.sh 'sudo docker run -dti -p 8082:8000 -e mongodb_url=mongodb://172.17.0.1:27017 -e base_url=http://testresults.opnfv.org/test opnfv/testapi' "http://testresults.opnfv.org/test/swagger/APIs" + bash ./jjb/releng/docker-deploy.sh "sudo docker run -dti -p 8082:8000 + -e mongodb_url=mongodb://172.17.0.1:27017 + -e base_url=http://testresults.opnfv.org/test opnfv/testapi" \ + "http://testresults.opnfv.org/test/swagger/APIs" "testapi" + - builder: name: 'reporting-automate-docker-deploy-macro' builders: - shell: | - bash ./jjb/releng/docker-deploy.sh 'sudo docker run -itd -p 8084:8000 opnfv/reporting' "http://testresults.opnfv.org/reporting2/reporting/index.html" + bash ./jjb/releng/docker-deploy.sh "sudo docker run -itd -p 8084:8000 opnfv/reporting" \ + "http://testresults.opnfv.org/reporting2/reporting/index.html" "reporting" - builder: name: mongodb-backup diff --git a/jjb/releng/docker-deploy.sh b/jjb/releng/docker-deploy.sh index b3b930fc4..2a3e078ae 100644 --- a/jjb/releng/docker-deploy.sh +++ b/jjb/releng/docker-deploy.sh @@ -19,6 +19,7 @@ # Assigning Variables command=$1 url=$2 +module=$3 function check() { @@ -38,24 +39,26 @@ function check() { } echo "Getting contianer Id of the currently running one" -contId=$(sudo docker ps | grep "opnfv/testapi:latest" | awk '{print $1}') +contId=$(sudo docker ps | grep "opnfv/${module}:latest" | awk '{print $1}') + +echo $contId echo "Pulling the latest image" -sudo docker pull opnfv/testapi:latest +sudo docker pull opnfv/${module}:latest -echo "Deleting old containers of opnfv/testapi:old" -sudo docker ps -a | grep "opnfv/testapi" | grep "old" | awk '{print $1}' | xargs -r sudo docker rm -f +echo "Deleting old containers of opnfv/${module}:old" +sudo docker ps -a | grep "opnfv/${module}" | grep "old" | awk '{print $1}' | xargs -r sudo docker rm -f -echo "Deleting old images of opnfv/testapi:latest" -sudo docker images | grep "opnfv/testapi" | grep "old" | awk '{print $3}' | xargs -r sudo docker rmi -f +echo "Deleting old images of opnfv/${module}:latest" +sudo docker images | grep "opnfv/${module}" | grep "old" | awk '{print $3}' | xargs -r sudo docker rmi -f if [[ -z "$contId" ]] then - echo "No running testapi container" + echo "No running ${module} container" - echo "Removing stopped testapi containers in the previous iterations" - sudo docker ps -f status=exited | grep "opnfv_testapi" | awk '{print $1}' | xargs -r sudo docker rm -f + echo "Removing stopped ${module} containers in the previous iterations" + sudo docker ps -f status=exited | grep "opnfv_${module}" | awk '{print $1}' | xargs -r sudo docker rm -f else echo $contId @@ -70,13 +73,13 @@ else fi echo "Changing current image tag to old" - sudo docker tag "$currImgId" opnfv/testapi:old + sudo docker tag "$currImgId" opnfv/${module}:old - echo "Removing stopped testapi containers in the previous iteration" - sudo docker ps -f status=exited | grep "opnfv_testapi" | awk '{print $1}' | xargs -r sudo docker rm -f + echo "Removing stopped ${module} containers in the previous iteration" + sudo docker ps -f status=exited | grep "opnfv_${module}" | awk '{print $1}' | xargs -r sudo docker rm -f - echo "Renaming the running container name to opnfv_testapi as to identify it." - sudo docker rename $contId opnfv_testapi + echo "Renaming the running container name to opnfv_${module} as to identify it." + sudo docker rename $contId opnfv_${module} echo "Stop the currently running container" sudo docker stop $contId @@ -86,10 +89,10 @@ echo "Running a container with the new image" $command:latest if check; then - echo "TestResults Hosted." + echo "TestResults Module Hosted." else - echo "TestResults Hosting Failed" - if [[ $(sudo docker images | grep "opnfv/testapi" | grep "old" | awk '{print $3}') ]]; then + echo "TestResults Module Failed" + if [[ $(sudo docker images | grep "opnfv/${module}" | grep "old" | awk '{print $3}') ]]; then echo "Running old Image" $command:old exit 1 -- 2.16.6