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 # Remove previous running containers if exist
21 if [[ -n "$(docker ps -a | grep $DOCKER_REPO_NAME)" ]]; then
22 echo "Removing existing $DOCKER_REPO_NAME containers..."
23 docker ps -a | grep $DOCKER_REPO_NAME | awk '{print $1}' | xargs docker rm -f
25 # Wait max 60 sec for containers to be removed
26 while [[ $t -gt 0 ]] && [[ -n "$(docker ps| grep $DOCKER_REPO_NAME)" ]]; do
33 # Remove existing images if exist
34 if [[ -n "$(docker images | grep $DOCKER_REPO_NAME)" ]]; then
35 echo "Docker images to remove:"
36 docker images | head -1 && docker images | grep $DOCKER_REPO_NAME
37 image_ids=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $3}'))
38 for id in "${image_ids[@]}"; do
39 if [[ -n "$(docker images|grep $DOCKER_REPO_NAME|grep $id)" ]]; then
40 echo "Removing docker image $DOCKER_REPO_NAME:$id..."
46 cd $WORKSPACE/$DOCKER_DIR
48 if [ ! -f "${DOCKERFILE}" ]; then
49 # If this is expected to be a Dockerfile for other arch than x86
50 # and it does not exist, but there is a patch for the said arch,
51 # then apply the patch and create the Dockerfile.${HOST_ARCH} file
52 if [[ "${DOCKERFILE}" == *"${HOST_ARCH}" && \
53 -f "Dockerfile.${HOST_ARCH}.patch" ]]; then
54 patch -o Dockerfile."${HOST_ARCH}" Dockerfile \
55 Dockerfile."${HOST_ARCH}".patch
57 echo "ERROR: No Dockerfile or ${HOST_ARCH} patch found."
63 echo "Current branch: $BRANCH"
67 if [[ "$BRANCH" == "master" ]]; then
69 elif [[ -n "${RELEASE_VERSION-}" ]]; then
70 DOCKER_TAG=${BRANCH##*/}.${RELEASE_VERSION}
71 # e.g. danube.1.0, danube.2.0, danube.3.0
76 if [[ -n "${COMMIT_ID-}" && -n "${RELEASE_VERSION-}" ]]; then
77 DOCKER_TAG=$RELEASE_VERSION
78 BUILD_BRANCH=$COMMIT_ID
82 ARCH_TAG=${ARCH_TAG:-}
83 if [[ -n "${ARCH_TAG}" ]]; then
84 DOCKER_TAG=${ARCH_TAG}-${DOCKER_TAG}
85 ARCH_BUILD_ARG="--build-arg ARCH=${ARCH_TAG}"
89 echo "Building docker image: $DOCKER_REPO_NAME:$DOCKER_TAG"
90 echo "--------------------------------------------------------"
92 cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG --build-arg BRANCH=$BUILD_BRANCH
101 echo "Available images are:"
104 # Push image to Dockerhub
105 if [[ "$PUSH_IMAGE" == "true" ]]; then
106 echo "Pushing $DOCKER_REPO_NAME:$DOCKER_TAG to the docker registry..."
107 echo "--------------------------------------------------------"
109 docker push $DOCKER_REPO_NAME:$DOCKER_TAG