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 "--------------------------------------------------------"
20 count=30 # docker build jobs might take up to ~30 min
21 while [[ -n `ps -ef|grep 'docker build'|grep -v grep` ]]; do
22 echo "Build in progress. Waiting..."
24 count=$(( $count - 1 ))
25 if [ $count -eq 0 ]; then
26 echo "Timeout. Aborting..."
31 # Remove previous running containers if exist
32 if [[ -n "$(docker ps -a | grep $DOCKER_REPO_NAME)" ]]; then
33 echo "Removing existing $DOCKER_REPO_NAME containers..."
34 docker ps -a | grep $DOCKER_REPO_NAME | awk '{print $1}' | xargs docker rm -f
36 # Wait max 60 sec for containers to be removed
37 while [[ $t -gt 0 ]] && [[ -n "$(docker ps| grep $DOCKER_REPO_NAME)" ]]; do
44 # Remove existing images if exist
45 if [[ -n "$(docker images | grep $DOCKER_REPO_NAME)" ]]; then
46 echo "Docker images to remove:"
47 docker images | head -1 && docker images | grep $DOCKER_REPO_NAME
48 image_ids=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $3}'))
49 for id in "${image_ids[@]}"; do
50 if [[ -n "$(docker images|grep $DOCKER_REPO_NAME|grep $id)" ]]; then
51 echo "Removing docker image $DOCKER_REPO_NAME:$id..."
59 if [ ! -f "${DOCKERFILE}" ]; then
60 # If this is expected to be a Dockerfile for other arch than x86
61 # and it does not exist, but there is a patch for the said arch,
62 # then apply the patch and create the Dockerfile.${HOST_ARCH} file
63 if [[ "${DOCKERFILE}" == *"${HOST_ARCH}" && \
64 -f "Dockerfile.${HOST_ARCH}.patch" ]]; then
65 patch -o Dockerfile."${HOST_ARCH}" Dockerfile \
66 Dockerfile."${HOST_ARCH}".patch
68 echo "ERROR: No Dockerfile or ${HOST_ARCH} patch found."
74 echo "Current branch: $BRANCH"
76 if [[ "$BRANCH" == "master" ]]; then
78 elif [[ -n "${RELEASE_VERSION-}" ]]; then
79 DOCKER_TAG=${BRANCH##*/}.${RELEASE_VERSION}
80 # e.g. danube.1.0, danube.2.0, danube.3.0
86 echo "Building docker image: $DOCKER_REPO_NAME:$DOCKER_TAG"
87 echo "--------------------------------------------------------"
89 if [[ $DOCKER_REPO_NAME == *"dovetail"* ]]; then
90 if [[ -n "${RELEASE_VERSION-}" ]]; then
91 DOCKER_TAG=${RELEASE_VERSION}
93 cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG -f $DOCKERFILE ."
95 cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG --build-arg BRANCH=$BRANCH
104 echo "Available images are:"
107 # Push image to Dockerhub
108 if [[ "$PUSH_IMAGE" == "true" ]]; then
109 echo "Pushing $DOCKER_REPO_NAME:$DOCKER_TAG to the docker registry..."
110 echo "--------------------------------------------------------"
112 docker push $DOCKER_REPO_NAME:$DOCKER_TAG