7 echo "Starting opnfv-docker for $DOCKER_REPO_NAME ..."
8 echo "--------------------------------------------------------"
12 # Remove previous running containers if exist
13 if [[ ! -z $(docker ps -a | grep $DOCKER_REPO_NAME) ]]; then
14 echo "Removing existing $DOCKER_REPO_NAME containers..."
15 #docker ps | grep $DOCKER_REPO_NAME | awk '{print $1}' | xargs docker stop
16 docker ps -a | grep $DOCKER_REPO_NAME | awk '{print $1}' | xargs docker rm -f
18 # Wait max 60 sec for containers to be removed
19 while [[ $t -gt 0 ]]; do
20 ids=$(docker ps | grep $DOCKER_REPO_NAME |awk '{print $1}')
21 if [[ -z $ids ]]; then
30 # Remove existing images if exist
31 if [[ ! -z $(docker images | grep $DOCKER_REPO_NAME) ]]; then
32 echo "Docker images to remove:"
33 docker images | head -1 && docker images | grep $DOCKER_REPO_NAME
34 image_tags=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $2}'))
35 for tag in "${image_tags[@]}"; do
36 echo "Removing docker image $DOCKER_REPO_NAME:$tag..."
37 docker rmi -f $DOCKER_REPO_NAME:$tag
41 # If we just want to update the latest_stable image
42 if [[ "$UPDATE_LATEST_STABLE" == "true" ]]; then
43 echo "Pulling $DOCKER_REPO_NAME:$STABLE_TAG ..."
44 docker pull $DOCKER_REPO_NAME:$STABLE_TAG
45 if [[ $? -ne 0 ]]; then
46 echo "ERROR: The image $DOCKER_REPO_NAME with tag $STABLE_TAG does not exist."
49 docker tag -f $DOCKER_REPO_NAME:$STABLE_TAG $DOCKER_REPO_NAME:latest_stable
50 echo "Pushing $DOCKER_REPO_NAME:latest_stable ..."
51 docker push $DOCKER_REPO_NAME:latest_stable
56 # cd to directory where Dockerfile is located
57 if [[ "$DOCKER_REPO_NAME" == "opnfv/functest" ]]; then
59 elif [[ "$DOCKER_REPO_NAME" == "opnfv/yardstick" ]]; then
60 cd $WORKSPACE/ci/docker/yardstick-ci
61 elif [[ "$DOCKER_REPO_NAME" == "opnfv/storperf" ]]; then
63 elif [[ "$DOCKER_REPO_NAME" == "opnfv/qtip" ]]; then
66 echo "ERROR: DOCKER_REPO_NAME parameter not valid: $DOCKER_REPO_NAME"
71 branch="${GIT_BRANCH##origin/}"
72 echo "Current branch: $branch"
74 if [[ "$branch" == "master" ]]; then
77 git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng
79 DOCKER_TAG=$($WORKSPACE/releng/utils/calculate_version.sh -t docker \
83 if [[ $ret_val -ne 0 ]]; then
84 echo "Error retrieving the version tag."
88 echo "Tag version to be build and pushed: $DOCKER_TAG"
92 echo "Building docker image: $DOCKER_REPO_NAME:$DOCKER_TAG..."
94 docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG .
95 echo "Creating tag 'latest'..."
96 docker tag $DOCKER_REPO_NAME:$DOCKER_TAG $DOCKER_REPO_NAME:latest
99 echo "Available images are:"
102 # Push image to Dockerhub
103 if [[ "$PUSH_IMAGE" == "true" ]]; then
104 echo "Pushing $DOCKER_REPO_NAME:$DOCKER_TAG to the docker registry..."
105 echo "--------------------------------------------------------"
107 # Push to the Dockerhub repository
108 docker push $DOCKER_REPO_NAME:$DOCKER_TAG
110 echo "Updating $DOCKER_REPO_NAME:latest to the docker registry..."
111 docker push $DOCKER_REPO_NAME:latest