set -o pipefail
+
echo "Starting opnfv-docker for $DOCKER_REPO_NAME ..."
echo "--------------------------------------------------------"
echo
if [[ -n "$(docker images | grep $DOCKER_REPO_NAME)" ]]; then
echo "Docker images to remove:"
docker images | head -1 && docker images | grep $DOCKER_REPO_NAME
- image_tags=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $2}'))
- for tag in "${image_tags[@]}"; do
- if [[ -n "$(docker images|grep $DOCKER_REPO_NAME|grep $tag)" ]]; then
- echo "Removing docker image $DOCKER_REPO_NAME:$tag..."
- docker rmi -f $DOCKER_REPO_NAME:$tag
+ image_ids=($(docker images | grep $DOCKER_REPO_NAME | awk '{print $3}'))
+ for id in "${image_ids[@]}"; do
+ if [[ -n "$(docker images|grep $DOCKER_REPO_NAME|grep $id)" ]]; then
+ echo "Removing docker image $DOCKER_REPO_NAME:$id..."
+ docker rmi -f $id
fi
done
fi
-
-# cd to directory where Dockerfile is located
cd $WORKSPACE/docker
-if [ ! -f ./Dockerfile ]; then
- echo "ERROR: Dockerfile not found."
- exit 1
+HOST_ARCH=$(uname -m)
+if [ ! -f "${DOCKERFILE}" ]; then
+ # If this is expected to be a Dockerfile for other arch than x86
+ # and it does not exist, but there is a patch for the said arch,
+ # then apply the patch and create the Dockerfile.${HOST_ARCH} file
+ if [[ "${DOCKERFILE}" == *"${HOST_ARCH}" && \
+ -f "Dockerfile.${HOST_ARCH}.patch" ]]; then
+ patch -o Dockerfile."${HOST_ARCH}" Dockerfile \
+ Dockerfile."${HOST_ARCH}".patch
+ else
+ echo "ERROR: No Dockerfile or ${HOST_ARCH} patch found."
+ exit 1
+ fi
fi
# Get tag version
-branch="${GIT_BRANCH##origin/}"
-echo "Current branch: $branch"
+echo "Current branch: $BRANCH"
-if [[ "$branch" == "master" ]]; then
+if [[ "$BRANCH" == "master" ]]; then
DOCKER_TAG="latest"
else
if [[ "$RELEASE_VERSION" != "" ]]; then
- release=$(echo $branch|sed 's/.*\///')
+ release=${BRANCH##*/}
DOCKER_TAG=${release}.${RELEASE_VERSION}
# e.g. colorado.1.0, colorado.2.0, colorado.3.0
else
echo "Building docker image: $DOCKER_REPO_NAME:$DOCKER_TAG"
echo "--------------------------------------------------------"
echo
-cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG --build-arg BRANCH=$branch ."
+if [[ $DOCKER_REPO_NAME == *"dovetail"* ]]; then
+ cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG -f $DOCKERFILE ."
+else
+ cmd="docker build --no-cache -t $DOCKER_REPO_NAME:$DOCKER_TAG --build-arg BRANCH=$BRANCH
+ -f $DOCKERFILE ."
+fi
echo ${cmd}
${cmd}