From 57c83817b33ad9035be534f7c160259cbf11be60 Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Wed, 11 Nov 2015 00:57:52 +0100 Subject: Add more if-else checks in functest docker build job Also: update image with tag 'latest' JIRA: FUNCTEST-78 Change-Id: Idd1e143ada44ddb86d0bcb21c1b9ba4ed89675fc Signed-off-by: jose.lausuch --- jjb/functest/functest-docker.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'jjb') diff --git a/jjb/functest/functest-docker.sh b/jjb/functest/functest-docker.sh index 883cb1b44..4de70d459 100644 --- a/jjb/functest/functest-docker.sh +++ b/jjb/functest/functest-docker.sh @@ -10,8 +10,12 @@ echo DOCKER_IMAGE_NAME="opnfv/functest" + # Get tag version -DOCKER_TAG=$(../../utils/calculate_version.sh -t docker -n $DOCKER_IMAGE_NAME) +cd $WORKSPACE +git clone https://gerrit.opnfv.org/gerrit/releng + +DOCKER_TAG=$($WORKSPACE/releng/utils/calculate_version.sh -t docker -n $DOCKER_IMAGE_NAME) ret_val=$? if [ $ret_val -ne 0 ]; then @@ -23,18 +27,24 @@ fi # Remove previous running containers echo "Removing existing $DOCKER_IMAGE_NAME containers..." -docker ps | grep $DOCKER_IMAGE_NAME | awk '{{print $1}}' | xargs docker stop &>/dev/null -docker ps -a | grep $DOCKER_IMAGE_NAME | awk '{{print $1}}' | xargs docker rm &>/dev/null +if [[ ! -z $(docker ps -a | grep $DOCKER_IMAGE_NAME) ]]; then + docker ps | grep $DOCKER_IMAGE_NAME | awk '{{print $1}}' | xargs docker stop &>/dev/null + docker ps -a | grep $DOCKER_IMAGE_NAME | awk '{{print $1}}' | xargs docker rm &>/dev/null +fi # Remove existing images echo "Removing existing $DOCKER_IMAGE_NAME images..." -docker images | grep $DOCKER_IMAGE_NAME | awk '{{print $3}}' | xargs docker rmi &>/dev/null +if [[ ! -z $(docker images | grep $DOCKER_IMAGE_NAME) ]]; then + docker images | grep $DOCKER_IMAGE_NAME | awk '{{print $3}}' | xargs docker rmi &>/dev/null +fi # Start the build -echo "Starting image build of $DOCKER_IMAGE_NAME:$DOCKER_TAG..." -cd $WORKSPACE/docker/ +echo "Building of $DOCKER_IMAGE_NAME:$DOCKER_TAG..." +cd $WORKSPACE/functest/docker docker build -t $DOCKER_IMAGE_NAME:$DOCKER_TAG . +echo "Creating tag 'latest'..." +docker tag $DOCKER_IMAGE_NAME:$DOCKER_TAG $DOCKER_IMAGE_NAME:latest # list the images echo "Available images are:" @@ -46,5 +56,8 @@ if [ "$PUSH_IMAGE" == "true" ]; then echo "--------------------------------------------------------" echo # Push to the Dockerhub repository - docker push $DOCKER_IMAGE_NAME:$DOCKER_TAG + docker push -f $DOCKER_IMAGE_NAME:$DOCKER_TAG + + echo "Updating $DOCKER_IMAGE_NAME:latest to the docker registry..." + docker push -f $DOCKER_IMAGE_NAME:latest fi -- cgit 1.2.3-korg