From d9c235cfa95733b36a0edf525a9c9ccc9429a818 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Wed, 21 Mar 2018 13:03:59 -0700 Subject: Add global docker jobs Add global build and push jobs for docker images Set proper docker tag convention for snapshot and staging binaries. Change-Id: I0e805b5c9eebac6aaea627d855d7b542158b6a0f Issue-ID: CIMAN-132 Signed-off-by: Jessica Wagantall Signed-off-by: Jeremy Phelps --- shell/docker-build.sh | 34 ++++++++++++++++++++++++++++++++++ shell/docker-push.sh | 6 ++++++ shell/snapshot-strip.sh | 6 ++++++ 3 files changed, 46 insertions(+) create mode 100644 shell/docker-build.sh create mode 100644 shell/docker-push.sh create mode 100644 shell/snapshot-strip.sh (limited to 'shell') diff --git a/shell/docker-build.sh b/shell/docker-build.sh new file mode 100644 index 000000000..3d633d088 --- /dev/null +++ b/shell/docker-build.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Ensure we fail the job if any steps fail +# Do not set -u as DOCKER_ARGS may be unbound +set -e -o pipefail + +FULL_DATE=`date +'%Y%m%dT%H%M%S'` +IMAGE_VERSION= $( xmlstarlet sel -N "x=http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:version" pom.xml | cut -c1-5 ) + +case $DOCKERREGISTRY in + '$DOCKER_REGISTRY:10004') DOCKER_TAG="$IMAGE_VERSION"-STAGING-"$FULL_DATE"Z + echo "Using tag $DOCKER_TAG" + ;; + '$DOCKER_REGISTRY:10003') DOCKER_TAG="$IMAGE_VERSION"-SNAPSHOT-"$FULL_DATE"Z + echo "Using tag $DOCKER_TAG" + ;; +esac + +# Switch to the directory where the Dockerfile is +cd "$DOCKER_ROOT" + +# DOCKERREGISTRY is purposely not using an '_' so as to not conflict with the +# Jenkins global env var of the DOCKER_REGISTRY which the docker-login step uses +IMAGE_NAME="$DOCKERREGISTRY/$DOCKER_NAME:$DOCKER_TAG" + +# Build the docker image + +# Allow word splitting +# shellcheck disable=SC2086 +docker build $DOCKER_ARGS . -t $IMAGE_NAME | tee "$WORKSPACE/docker_build_log.txt" + +# Write DOCKER_IMAGE information to a file so it can be injected into the +# environment for following steps +echo "DOCKER_IMAGE=$IMAGE_NAME" >> "$WORKSPACE/env_inject.txt" + diff --git a/shell/docker-push.sh b/shell/docker-push.sh new file mode 100644 index 000000000..68b2bdb95 --- /dev/null +++ b/shell/docker-push.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Ensure we fail the job if any steps fail +set -e -o pipefail + +# Push our image to wherever it's defined to go by the name +docker push "$DOCKER_IMAGE" diff --git a/shell/snapshot-strip.sh b/shell/snapshot-strip.sh new file mode 100644 index 000000000..a418a75b0 --- /dev/null +++ b/shell/snapshot-strip.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Ensure we fail the job if any steps fail +set -e -o pipefail + +# Strip -SNAPSHOT from pom +find . -name "*.xml" -print0 | xargs -0 sed -i 's/-SNAPSHOT//g' -- cgit 1.2.3-korg