summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@linuxfoundation.org>2018-03-21 13:03:59 -0700
committerJeremy Phelps <jphelps@linuxfoundation.org>2018-04-03 07:55:13 -0500
commitd9c235cfa95733b36a0edf525a9c9ccc9429a818 (patch)
tree489bb00196d01f6b608795544f583afac4f588ec
parent02611ea91bd1bdc993e261b75b2426449a9e031d (diff)
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 <jwagantall@linuxfoundation.org> Signed-off-by: Jeremy Phelps <jphelps@linuxfoundation.org>
-rw-r--r--jjb/global-templates-docker.yaml344
-rw-r--r--shell/docker-build.sh34
-rw-r--r--shell/docker-push.sh6
-rw-r--r--shell/snapshot-strip.sh6
4 files changed, 390 insertions, 0 deletions
diff --git a/jjb/global-templates-docker.yaml b/jjb/global-templates-docker.yaml
new file mode 100644
index 000000000..8650086e6
--- /dev/null
+++ b/jjb/global-templates-docker.yaml
@@ -0,0 +1,344 @@
+---
+###########
+# ANCHORS #
+###########
+- docker_job_boiler_plate: &docker_job_boiler_plate
+ name: docker_job_boiler_plate
+
+ project-type: freestyle
+ node: '{build-node}'
+
+ ######################
+ # Default parameters #
+ ######################
+
+ branch: master
+ submodule-recursive: true
+
+ # default params for docker jobs
+ pre_build_script: ''
+ post_build_script: ''
+ docker_root: '$WORKSPACE'
+ docker_build_args: ''
+ docker_name: 'unnamed'
+ # Default to LF standard 'snapshots' docker registry
+ docker_registry: '$DOCKER_REGISTRY:10003'
+ docker_tag: 'latest'
+
+ #####################
+ # Job Configuration #
+ #####################
+
+ properties:
+ - lf-infra-properties:
+ build-days-to-keep: '{build-days-to-keep}'
+
+ parameters:
+ - lf-infra-parameters:
+ branch: '{branch}'
+ project: '{project}'
+ stream: '{stream}'
+ lftools-version: '{lftools-version}'
+
+ wrappers:
+ - lf-infra-wrappers:
+ build-timeout: '{build-timeout}'
+ jenkins-ssh-credential: '{jenkins-ssh-credential}'
+
+ publishers:
+ - lf-infra-publish
+
+- docker_verify_boiler_plate: &docker_verify_boiler_plate
+ name: docker_verify_boiler_plate
+
+ concurrent: true
+
+ scm:
+ - gerrit-trigger-scm:
+ refspec: '$GERRIT_REFSPEC'
+ choosing-strategy: 'default'
+ submodule-recursive: '{submodule-recursive}'
+
+ triggers:
+ - gerrit-trigger-patch-submitted:
+ status-context: '{project}-Docker-Verify'
+ server: '{server-name}'
+ project: '{project}'
+ branch: '{branch}'
+
+- docker_merge_boiler_plate: &docker_merge_boiler_plate
+ name: docker_merge_boiler_plate
+
+ scm:
+ - gerrit-trigger-scm:
+ refspec: '$GERRIT_REFSPEC'
+ choosing-strategy: 'default'
+ submodule-recursive: '{submodule-recursive}'
+
+ triggers:
+ - gerrit-trigger-patch-merged:
+ server: '{server-name}'
+ project: '{project}'
+ branch: '{branch}'
+ files: '**'
+ - pollscm:
+ cron: ''
+
+#################
+# JOB TEMPLATES #
+#################
+- job-template:
+ name: '{project-name}-{stream}-merge-docker'
+ # Job template for Docker merge jobs
+ #
+ # The purpose of this job template is to run a docker build, and potentially
+ # test validation of the docker image
+
+ <<: *docker_job_boiler_plate
+ # yamllint disable-line rule:key-duplicates
+ <<: *docker_merge_boiler_plate
+
+ builders:
+ - lf-infra-docker-login:
+ global-settings-file: 'global-settings'
+ settings-file: '{mvn-settings}'
+ - shell: '{pre_build_script}'
+ - inject:
+ # Docker registry is purposely not using an '_' so as to not conflict
+ # with the Jenkins global env var
+ properties-content: |
+ DOCKER_ARGS={docker_build_args}
+ DOCKER_NAME={docker_name}
+ DOCKER_ROOT={docker_root}
+ DOCKER_TAG={docker_tag}
+ DOCKERREGISTRY={docker_registry}
+ # Do the docker build
+ - shell: !include-raw: ../shell/docker-build.sh
+ - inject:
+ # Import the docker image information from the build step
+ properties-file: 'env_inject.txt'
+ # Execute any post build clean-up or testing
+ - shell: '{post_build_script}'
+ # Provided all steps have already passed, push the docker image
+ - shell: !include-raw: ../shell/docker-push.sh
+
+- job-template:
+ name: '{project-name}-{stream}-verify-docker'
+ # Job template for Docker verify jobs
+ #
+ # The purpose of this job template is to run a docker build, and potentially
+ # test validation of the docker image
+
+ ######################
+ # Default parameters #
+ ######################
+
+ <<: *docker_job_boiler_plate
+ # yamllint disable-line rule:key-duplicates
+ <<: *docker_verify_boiler_plate
+
+ builders:
+ - lf-infra-docker-login:
+ global-settings-file: 'global-settings'
+ settings-file: '{mvn-settings}'
+ - shell: '{pre_build_script}'
+ - inject:
+ # Docker registry is purposely not using an '_' so as to not conflict
+ # with the Jenkins global env var
+ properties-content: |
+ DOCKER_ARGS={docker_build_args}
+ DOCKER_NAME={docker_name}
+ DOCKER_ROOT={docker_root}
+ DOCKER_TAG={docker_tag}
+ DOCKERREGISTRY={docker_registry}
+ # Do the docker build
+ - shell: !include-raw: ../shell/docker-build.sh
+ - inject:
+ # Import the docker image information from the build step
+ properties-file: 'env_inject.txt'
+ # Execute any post build clean-up or testing
+ - shell: '{post_build_script}'
+
+- job-template:
+ name: '{project-name}-{stream}-release-version-docker-daily-no-sonar'
+ # Job template for Docker daily release jobs
+ #
+ # The purpose of this job template is to run "docker build and docker push"
+ # for projects using this template.
+ #
+ # Required Variables:
+ # branch: git branch (eg. stable/lithium or master)
+ <<: *docker_job_boiler_plate
+
+ docker_registry: '$DOCKER_REGISTRY:10004'
+
+ scm:
+ - lf-infra-gerrit-scm:
+ jenkins-ssh-credential: '{jenkins-ssh-credential}'
+ git-url: '$GIT_URL/$PROJECT'
+ refspec: '$GERRIT_REFSPEC'
+ branch: '$GERRIT_BRANCH'
+ submodule-recursive: true
+ choosing-strategy: default
+
+ builders:
+ - lf-infra-docker-login:
+ global-settings-file: 'global-settings'
+ settings-file: '{mvn-settings}'
+ - shell: '{pre_build_script}'
+ - inject:
+ # Docker registry is purposely not using an '_' so as to not conflict
+ # with the Jenkins global env var
+ properties-content: |
+ DOCKER_ARGS={docker_build_args}
+ DOCKER_NAME={docker_name}
+ DOCKER_ROOT={docker_root}
+ DOCKER_TAG={docker_tag}
+ DOCKERREGISTRY={docker_registry}
+
+ # Do the docker build
+ - shell: !include-raw: ../shell/snapshot-strip.sh
+ - shell: !include-raw: ../shell/docker-build.sh
+ - inject:
+ # Import the docker image information from the build step
+ properties-file: 'env_inject.txt'
+ # Execute any post build clean-up or testing
+ - shell: '{post_build_script}'
+ # Provided all steps have already passed, push the docker image
+ - shell: !include-raw: ../shell/docker-push.sh
+
+ triggers:
+ # 11 AM UTC
+ - timed: 'H 11 * * *'
+ - gerrit-trigger-release-manually:
+ server: '{server-name}'
+ project: '{project}'
+ branch: '{branch}'
+
+- job-template:
+ name: '{project-name}-{subproject}-{stream}-merge-docker'
+ # Job template for Docker merge jobs
+ #
+ # The purpose of this job template is to run a docker build, and potentially
+ # test validation of the docker image
+
+ <<: *docker_job_boiler_plate
+ # yamllint disable-line rule:key-duplicates
+ <<: *docker_merge_boiler_plate
+
+ builders:
+ - lf-infra-docker-login:
+ global-settings-file: 'global-settings'
+ settings-file: '{mvn-settings}'
+ - shell: '{pre_build_script}'
+ - inject:
+ # Docker registry is purposely not using an '_' so as to not conflict
+ # with the Jenkins global env var
+ properties-content: |
+ DOCKER_ARGS={docker_build_args}
+ DOCKER_NAME={docker_name}
+ DOCKER_ROOT={docker_root}
+ DOCKER_TAG={docker_tag}
+ DOCKERREGISTRY={docker_registry}
+ # Do the docker build
+ - shell: !include-raw: ../shell/docker-build.sh
+ - inject:
+ # Import the docker image information from the build step
+ properties-file: 'env_inject.txt'
+ # Execute any post build clean-up or testing
+ - shell: '{post_build_script}'
+ # Provided all steps have already passed, push the docker image
+ - shell: !include-raw: ../shell/docker-push.sh
+
+- job-template:
+ name: '{project-name}-{subproject}-{stream}-verify-docker'
+ # Job template for Docker verify jobs
+ #
+ # The purpose of this job template is to run a docker build, and potentially
+ # test validation of the docker image
+
+ ######################
+ # Default parameters #
+ ######################
+
+ <<: *docker_job_boiler_plate
+ # yamllint disable-line rule:key-duplicates
+ <<: *docker_verify_boiler_plate
+
+ builders:
+ - lf-infra-docker-login:
+ global-settings-file: 'global-settings'
+ settings-file: '{mvn-settings}'
+ - shell: '{pre_build_script}'
+ - inject:
+ # Docker registry is purposely not using an '_' so as to not conflict
+ # with the Jenkins global env var
+ properties-content: |
+ DOCKER_ARGS={docker_build_args}
+ DOCKER_NAME={docker_name}
+ DOCKER_ROOT={docker_root}
+ DOCKER_TAG={docker_tag}
+ DOCKERREGISTRY={docker_registry}
+ # Do the docker build
+ - shell: !include-raw: ../shell/docker-build.sh
+ - inject:
+ # Import the docker image information from the build step
+ properties-file: 'env_inject.txt'
+ # Execute any post build clean-up or testing
+ - shell: '{post_build_script}'
+
+- job-template:
+ name: '{project-name}-{subproject}-{stream}-release-version-docker-daily-no-sonar'
+ # Job template for Docker daily release jobs
+ #
+ # The purpose of this job template is to run "docker build and docker push"
+ # for projects using this template.
+ #
+ # Required Variables:
+ # branch: git branch (eg. stable/lithium or master)
+ <<: *docker_job_boiler_plate
+
+ docker_registry: '$DOCKER_REGISTRY:10004'
+
+ scm:
+ - lf-infra-gerrit-scm:
+ jenkins-ssh-credential: '{jenkins-ssh-credential}'
+ git-url: '$GIT_URL/$PROJECT'
+ refspec: '$GERRIT_REFSPEC'
+ branch: '$GERRIT_BRANCH'
+ submodule-recursive: true
+ choosing-strategy: default
+
+ builders:
+ - lf-infra-docker-login:
+ global-settings-file: 'global-settings'
+ settings-file: '{mvn-settings}'
+ - shell: '{pre_build_script}'
+ - inject:
+ # Docker registry is purposely not using an '_' so as to not conflict
+ # with the Jenkins global env var
+ properties-content: |
+ DOCKER_ARGS={docker_build_args}
+ DOCKER_NAME={docker_name}
+ DOCKER_ROOT={docker_root}
+ DOCKER_TAG={docker_tag}
+ DOCKERREGISTRY={docker_registry}
+
+ # Do the docker build
+ - shell: !include-raw: ../shell/snapshot-strip.sh
+ - shell: !include-raw: ../shell/docker-build.sh
+ - inject:
+ # Import the docker image information from the build step
+ properties-file: 'env_inject.txt'
+ # Execute any post build clean-up or testing
+ - shell: '{post_build_script}'
+ # Provided all steps have already passed, push the docker image
+ - shell: !include-raw: ../shell/docker-push.sh
+
+ triggers:
+ # 11 AM UTC
+ - timed: 'H 11 * * *'
+ - gerrit-trigger-release-manually:
+ server: '{server-name}'
+ project: '{project}'
+ branch: '{branch}'
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'