2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
16 echo "Starting opnfv-docker for $DOCKER_REPO_NAME ..."
17 echo "--------------------------------------------------------"
21 if [[ -n $(ps -ef|grep 'docker build'|grep -v grep) ]]; then
22 echo "There is already another build process in progress:"
23 echo $(ps -ef|grep 'docker build'|grep -v grep)
24 # Abort this job since it will collide and might mess up the current one.
29 # Remove previous running containers if exist
30 if [[ -n "$(docker ps -a | grep $DOCKER_REPO_NAME)" ]]; then
31 echo "Removing existing $DOCKER_REPO_NAME containers..."
32 docker ps -a | grep $DOCKER_REPO_NAME | awk '{print $1}' | xargs docker rm -f
34 # Wait max 60 sec for containers to be removed
35 while [[ $t -gt 0 ]] && [[ -n "$(docker ps| grep $DOCKER_REPO_NAME)" ]]; do
42 # Remove existing images if exist
43 if [[ -n "$(docker images | grep $DOCKER_REPO_NAME)" ]]; then
44 echo "Docker images to remove:"
45 docker images | head -1 && docker images | grep $DOCKER_REPO_NAME
46 image_ids=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $3}'))
47 for id in "${image_ids[@]}"; do
48 if [[ -n "$(docker images|grep $DOCKER_REPO_NAME|grep $id)" ]]; then
49 echo "Removing docker image $DOCKER_REPO_NAME:$id..."
57 if [ ! -f "${DOCKERFILE}" ]; then
58 # If this is expected to be a Dockerfile for other arch than x86
59 # and it does not exist, but there is a patch for the said arch,
60 # then apply the patch and create the Dockerfile.${HOST_ARCH} file
61 if [[ "${DOCKERFILE}" == *"${HOST_ARCH}" && \
62 -f "Dockerfile.${HOST_ARCH}.patch" ]]; then
63 patch -o Dockerfile."${HOST_ARCH}" Dockerfile \
64 Dockerfile."${HOST_ARCH}".patch
66 echo "ERROR: No Dockerfile or ${HOST_ARCH} patch found."
72 echo "Current branch: $BRANCH"
74 if [[ "$BRANCH" == "master" ]]; then
77 if [[ -n "${RELEASE_VERSION-}" ]]; then
79 DOCKER_TAG=${release}.${RELEASE_VERSION}
80 # e.g. colorado.1.0, colorado.2.0, colorado.3.0
87 echo "Building docker image: $DOCKER_REPO_NAME:$DOCKER_TAG"
88 echo "--------------------------------------------------------"
90 if [[ $DOCKER_REPO_NAME == *"dovetail"* ]]; then
91 cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG -f $DOCKERFILE ."
93 cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG --build-arg BRANCH=$BRANCH
102 echo "Available images are:"
105 # Push image to Dockerhub
106 if [[ "$PUSH_IMAGE" == "true" ]]; then
107 echo "Pushing $DOCKER_REPO_NAME:$DOCKER_TAG to the docker registry..."
108 echo "--------------------------------------------------------"
110 docker push $DOCKER_REPO_NAME:$DOCKER_TAG