blob: 1cb71d3fff76ef1867592f0ae421b68cb5bc685b [file] [log] [blame]
Jessica Wagantalld9c235c2018-03-21 13:03:59 -07001#!/bin/bash
2# Ensure we fail the job if any steps fail
3# Do not set -u as DOCKER_ARGS may be unbound
4set -e -o pipefail
5
6FULL_DATE=`date +'%Y%m%dT%H%M%S'`
Jessica Wagantallfd057a02018-04-03 15:33:18 -07007IMAGE_VERSION=`xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" pom.xml | cut -c1-5`
Jessica Wagantalld9c235c2018-03-21 13:03:59 -07008
Denes Nemethbb2815b2018-05-15 22:12:54 +02009case "$BUILD_MODE" in
10 "STAGING")
Denes Nemeth801d2a62018-05-12 09:40:20 +020011 DOCKER_TAG="$IMAGE_VERSION"-STAGING-"$FULL_DATE"Z
12 DOCKER_LATEST_TAG="$IMAGE_VERSION"-STAGING-latest
13 echo "Using tags $DOCKER_TAG and $DOCKER_LATEST_TAG"
Jessica Wagantalld9c235c2018-03-21 13:03:59 -070014 ;;
Denes Nemethbb2815b2018-05-15 22:12:54 +020015 "SNAPSHOT")
Denes Nemeth801d2a62018-05-12 09:40:20 +020016 DOCKER_TAG="$IMAGE_VERSION"-SNAPSHOT-"$FULL_DATE"Z
17 DOCKER_LATEST_TAG="$IMAGE_VERSION"-SNAPSHOT-latest
18 echo "Using tags $DOCKER_TAG and $DOCKER_LATEST_TAG"
Jessica Wagantalld9c235c2018-03-21 13:03:59 -070019 ;;
20esac
21
22# Switch to the directory where the Dockerfile is
23cd "$DOCKER_ROOT"
24
25# DOCKERREGISTRY is purposely not using an '_' so as to not conflict with the
26# Jenkins global env var of the DOCKER_REGISTRY which the docker-login step uses
27IMAGE_NAME="$DOCKERREGISTRY/$DOCKER_NAME:$DOCKER_TAG"
Denes Nemeth801d2a62018-05-12 09:40:20 +020028IMAGE_NAME_LATEST="$DOCKERREGISTRY/$DOCKER_NAME:$DOCKER_LATEST_TAG"
Jessica Wagantalld9c235c2018-03-21 13:03:59 -070029
30# Build the docker image
31
32# Allow word splitting
33# shellcheck disable=SC2086
Denes Nemeth801d2a62018-05-12 09:40:20 +020034docker build $DOCKER_ARGS . -t $IMAGE_NAME -t $IMAGE_NAME_LATEST | tee "$WORKSPACE/docker_build_log.txt"
Jessica Wagantalld9c235c2018-03-21 13:03:59 -070035
36# Write DOCKER_IMAGE information to a file so it can be injected into the
37# environment for following steps
38echo "DOCKER_IMAGE=$IMAGE_NAME" >> "$WORKSPACE/env_inject.txt"
Denes Nemeth801d2a62018-05-12 09:40:20 +020039echo "DOCKER_IMAGE_LATEST=$IMAGE_NAME_LATEST" >> "$WORKSPACE/env_inject.txt"
40
Jessica Wagantalld9c235c2018-03-21 13:03:59 -070041