From 3b6730ee26430ef6cee960284ac914147a6b9b68 Mon Sep 17 00:00:00 2001 From: "Lott, Christopher (cl778h)" Date: Wed, 1 May 2019 13:32:13 +1000 Subject: [PATCH] Define maven + docker verify, merge and stage jobs This generalizes work first done for Acumos Java projects that build a Spring-Boot application into a Docker image, and do not need to deploy any jar libraries or POM files. Change-Id: Id8040fe2d32ffe4f682f80ec5c4ed60327ef56bd Signed-off-by: Lott, Christopher (cl778h) Signed-off-by: Jessica Wagantall Signed-off-by: Anil Belur --- .jjb-test/lf-maven-docker-jobs.yaml | 41 +++ docs/jjb/lf-maven-jobs.rst | 83 +++++- jjb/lf-maven-docker-job-groups.yaml | 22 ++ jjb/lf-maven-jobs.yaml | 313 +++++++++++++++++++++ ...dd-maven-docker-templates-6a515a99e5442dc2.yaml | 6 + 5 files changed, 461 insertions(+), 4 deletions(-) create mode 100644 .jjb-test/lf-maven-docker-jobs.yaml create mode 100644 jjb/lf-maven-docker-job-groups.yaml create mode 100644 releasenotes/notes/add-maven-docker-templates-6a515a99e5442dc2.yaml diff --git a/.jjb-test/lf-maven-docker-jobs.yaml b/.jjb-test/lf-maven-docker-jobs.yaml new file mode 100644 index 00000000..f0f4a2e0 --- /dev/null +++ b/.jjb-test/lf-maven-docker-jobs.yaml @@ -0,0 +1,41 @@ +--- +- project: + name: gerrit-maven-docker-jobs + jobs: + - gerrit-maven-docker-merge + - gerrit-maven-docker-stage + - gerrit-maven-docker-verify + + project-name: gerrit-maven-docker + container-public-registry: pub-registry + container-snapshot-registry: snap-registry + container-staging-registry: stage-registry + javadoc-path: org.example.project/$STREAM + staging-profile-id: uuddlrlrba + mvn-settings: gerrit-maven-project-settings + mvn-snapshot-id: fakeproject-snapshots + nexus-snapshot-repo: fakeproject-snapshots + +- project: + name: github-maven-docker-jobs + jobs: + - github-maven-docker-merge + - github-maven-docker-stage + - github-maven-docker-verify + + project-name: github-maven-docker + container-public-registry: pub-registry + container-snapshot-registry: snap-registry + container-staging-registry: stage-registry + javadoc-path: org.example.project/$STREAM + staging-profile-id: uuddlrlrba + mvn-settings: aproject-settings + mvn-snapshot-id: fakeproject-snapshots + nexus-snapshot-repo: fakeproject-snapshots + +- project: + name: maven-docker-jobs-view + views: + - project-view + + project-name: maven-docker diff --git a/docs/jjb/lf-maven-jobs.rst b/docs/jjb/lf-maven-jobs.rst index 575117e6..b911d9e3 100644 --- a/docs/jjb/lf-maven-jobs.rst +++ b/docs/jjb/lf-maven-jobs.rst @@ -75,7 +75,7 @@ Conditionally calls Maven versions plugin to set, update and commit the maven `v :mvn-settings: Maven settings.xml file containing credentials to use. lf-maven-stage ---------------- +-------------- Calls the maven stage script to push artifacts to a Nexus staging repository. @@ -293,11 +293,37 @@ This job uses the following strategy to deploy jobs to Nexus: (default: true) :submodule-timeout: Timeout (in minutes) for checkout operation. (default: 10) - :gerrit_merge_triggers: Override Gerrit Triggers. :gerrit_trigger_file_paths: Override file paths which can be used to filter which file modifications will trigger a build. +Maven Merge for Docker +---------------------- + +Produces a snapshot docker image in a Nexus registry. Appropriate for +Java projects that do not need to deploy any POM or JAR files. + +Similar to Maven Merge as described above but logs in to Docker +registries first and skips the lf-maven-deploy builder. The project +POM file should invoke a plugin to build and push a Docker image. The +base image should be pulled from the registry in the environment +variable CONTAINER_PULL_REGISTRY. The new image should be pushed to the +registry in the environment variable CONTAINER_PUSH_REGISTRY. + +:Template Names: + + - {project-name}-maven-docker-merge-{stream} + - gerrit-maven-docker-merge + - github-maven-docker-merge + +:Required parameters: + + :container-public-registry: Docker registry source with base images. + :container-snapshot-registry: Docker registry target for the deploy action. + +All other required and optional parameters are identical to the Maven Merge job +described above. + Maven Stage ----------- @@ -359,6 +385,34 @@ directory is then used later to deploy to Nexus. :gerrit_release_triggers: Override Gerrit Triggers. +Maven Stage for Docker +---------------------- + +Produces a release candidate docker image in a Nexus registry. +Appropriate for Java projects that do not need to deploy any POM or +JAR files. + +Similar to Maven Stage as described above but logs in to Docker +registries first and skips the lf-maven-deploy builder. The project +POM file should invoke a plugin to build and push a Docker image. The +base image should be pulled from the registry in the environment +variable CONTAINER_PULL_REGISTRY. The new image should be pushed to the +registry in the environment variable CONTAINER_PUSH_REGISTRY. + +:Template Names: + + - {project-name}-maven-docker-stage-{stream} + - gerrit-maven-docker-stage + - github-maven-docker-stage + +:Required parameters: + + :container-public-registry: Docker registry source with base images. + :container-staging-registry: Docker registry target for the deploy action. + +All other required and optional parameters are identical to the Maven Stage job +described above. + .. _maven-sonar: Maven Sonar @@ -466,7 +520,28 @@ Verify job which runs mvn clean install to test a project build.. :gerrit_trigger_file_paths: Override file paths which can be used to filter which file modifications will trigger a build. -Maven Verify /w Dependencies +Maven Verify for Docker +----------------------- + +Similar to Maven Verify as described above but logs in to Docker +registries first. The project POM file should invoke a plugin to build +a Docker image. The base image should be pulled from the registry in +the environment variable CONTAINER_PULL_REGISTRY. + +:Template Names: + + - {project-name}-maven-docker-verify-{stream}-{mvn-version}-{java-version} + - gerrit-maven-docker-verify + - github-maven-docker-verify + +:Required parameters: + + :container-public-registry: Docker registry source with base images. + +All other required and optional parameters are identical to the Maven Verify job +described above. + +Maven Verify w/ Dependencies ---------------------------- Verify job which runs mvn clean install to test a project build /w deps @@ -480,7 +555,7 @@ via comment trigger. - {project-name}-maven-verify-deps-{stream}-{mvn-version}-{java-version} - gerrit-maven-verify-dependencies -:Comment Trigger: recheck: SPACE_SEPERATED_LIST_OF_PATCHES +:Comment Trigger: recheck: SPACE_SEPARATED_LIST_OF_PATCHES :Required parameters: diff --git a/jjb/lf-maven-docker-job-groups.yaml b/jjb/lf-maven-docker-job-groups.yaml new file mode 100644 index 00000000..afeee903 --- /dev/null +++ b/jjb/lf-maven-docker-job-groups.yaml @@ -0,0 +1,22 @@ +--- +- job-group: + name: '{project-name}-maven-docker-jobs' + + # This job group contains all the recommended jobs that should be deployed + # for any maven docker project. + + jobs: + - gerrit-maven-docker-merge + - gerrit-maven-docker-stage + - gerrit-maven-docker-verify + +- job-group: + name: '{project-name}-github-maven-docker-jobs' + + # This job group contains all the recommended jobs that should be deployed + # for any maven docker project that is using github. + + jobs: + - github-maven-docker-merge + - github-maven-docker-stage + - github-maven-docker-verify diff --git a/jjb/lf-maven-jobs.yaml b/jjb/lf-maven-jobs.yaml index 4342a8f6..70251b80 100644 --- a/jjb/lf-maven-jobs.yaml +++ b/jjb/lf-maven-jobs.yaml @@ -672,6 +672,115 @@ - '{branch}' included-regions: '{obj:github_included_regions}' +########################## +# Maven Merge for Docker # +########################## + +- lf_maven_docker_merge: &lf_maven_docker_merge + name: lf-maven-docker-merge + + builders: + - lf-infra-pre-build + - lf-jacoco-nojava-workaround + - lf-maven-install: + mvn-version: '{mvn-version}' + - lf-infra-docker-login: + global-settings-file: '{mvn-global-settings}' + settings-file: '{mvn-settings}' + - lf-update-java-alternatives: + java-version: '{java-version}' + # must provide maven settings AFTER docker due to its cleanup + - lf-provide-maven-settings: + global-settings-file: '{mvn-global-settings}' + settings-file: '{mvn-settings}' + - lf-infra-create-netrc: + server-id: '{mvn-snapshot-id}' + - inject: + properties-content: | + NEXUS_CUT_DIRS={nexus-cut-dirs} + NEXUS_REPO={nexus-snapshot-repo} + CONTAINER_PULL_REGISTRY={container-public-registry} + CONTAINER_PUSH_REGISTRY={container-snapshot-registry} + - shell: !include-raw-escape: ../shell/maven-fetch-metadata.sh + - lf-maven-build: + mvn-goals: '{mvn-goals}' + # NO lf-maven-deploy + - lf-provide-maven-settings-cleanup + +- job-template: + name: '{project-name}-maven-docker-merge-{stream}' + id: gerrit-maven-docker-merge + <<: *lf_maven_common + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_merge + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_docker_merge + + scm: + - lf-infra-gerrit-scm: + jenkins-ssh-credential: '{jenkins-ssh-credential}' + git-url: '{git-url}' + refspec: '$GERRIT_REFSPEC' + branch: '$GERRIT_BRANCH' + submodule-recursive: '{submodule-recursive}' + submodule-timeout: '{submodule-timeout}' + choosing-strategy: default + + triggers: + - gerrit: + server-name: '{gerrit-server-name}' + trigger-on: '{obj:gerrit_merge_triggers}' + projects: + - project-compare-type: ANT + project-pattern: '{project}' + branches: + - branch-compare-type: ANT + branch-pattern: '**/{branch}' + file-paths: '{obj:gerrit_trigger_file_paths}' + +- job-template: + name: '{project-name}-maven-docker-merge-{stream}' + id: github-maven-docker-merge + <<: *lf_maven_common + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_merge + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_docker_merge + + properties: + - lf-infra-properties: + build-days-to-keep: '{build-days-to-keep}' + - github: + url: '{github-url}/{github-org}/{project}' + + scm: + - lf-infra-github-scm: + url: '{git-clone-url}{github-org}/{project}' + refspec: '' + branch: 'refs/heads/{branch}' + submodule-recursive: '{submodule-recursive}' + submodule-timeout: '{submodule-timeout}' + choosing-strategy: default + jenkins-ssh-credential: '{jenkins-ssh-credential}' + + triggers: + - github + - pollscm: + cron: '' + - github-pull-request: + trigger-phrase: '^remerge$' + only-trigger-phrase: true + status-context: 'Maven Docker Merge' + permit-all: true + github-hooks: true + org-list: + - '{github-org}' + white-list: '{obj:github_pr_whitelist}' + admin-list: '{obj:github_pr_admin_list}' + white-list-target-branches: + - '{branch}' + included-regions: '{obj:github_included_regions}' + ############### # Maven Stage # ############### @@ -837,6 +946,115 @@ white-list-target-branches: - '{branch}' +########################## +# Maven Stage for Docker # +########################## + +- lf_maven_docker_stage: &lf_maven_docker_stage + name: lf-maven-docker-stage + + builders: + - lf-infra-pre-build + - lf-jacoco-nojava-workaround + - lf-maven-install: + mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' + - lf-infra-docker-login: + global-settings-file: '{mvn-global-settings}' + settings-file: '{mvn-settings}' + # must provide maven settings AFTER docker-login due to its cleanup + - lf-provide-maven-settings: + global-settings-file: '{mvn-global-settings}' + settings-file: '{mvn-settings}' + - shell: !include-raw-escape: ../shell/maven-patch-release.sh + - lf-maven-versions-plugin: + maven-versions-plugin: '{maven-versions-plugin}' + mvn-version: '{mvn-version}' + mvn-pom: '{mvn-pom}' + maven-versions-plugin-set-version: '{maven-versions-plugin-set-version}' + mvn-settings: '{mvn-settings}' + - inject: + properties-content: | + CONTAINER_PULL_REGISTRY={container-public-registry} + CONTAINER_PUSH_REGISTRY={container-staging-registry} + - lf-maven-build: + mvn-goals: '{mvn-goals}' + - lf-sigul-sign-dir: + sign-artifacts: '{sign-artifacts}' + sign-dir: '$WORKSPACE/m2repo' + sign-mode: '{sign-mode}' + # NO lf-maven-stage + # NO lf-maven-central + - lf-provide-maven-settings-cleanup + +- job-template: + name: '{project-name}-maven-docker-stage-{stream}' + id: gerrit-maven-docker-stage + <<: *lf_maven_common + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_stage + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_docker_stage + + scm: + - lf-infra-gerrit-scm: + jenkins-ssh-credential: '{jenkins-ssh-credential}' + git-url: '{git-url}' + refspec: '$GERRIT_REFSPEC' + branch: '$GERRIT_BRANCH' + submodule-recursive: '{submodule-recursive}' + submodule-timeout: '{submodule-timeout}' + choosing-strategy: default + + triggers: + - timed: '{obj:cron}' + - gerrit: + server-name: '{gerrit-server-name}' + trigger-on: '{obj:gerrit_release_triggers}' + projects: + - project-compare-type: ANT + project-pattern: '{project}' + branches: + - branch-compare-type: ANT + branch-pattern: '**/{branch}' + +- job-template: + name: '{project-name}-maven-docker-stage-{stream}' + id: github-maven-docker-stage + <<: *lf_maven_common + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_stage + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_docker_stage + + properties: + - lf-infra-properties: + build-days-to-keep: '{build-days-to-keep}' + - github: + url: '{github-url}/{github-org}/{project}' + + scm: + - lf-infra-github-scm: + url: '{git-clone-url}{github-org}/{project}' + refspec: '+refs/pull/*:refs/remotes/origin/pr/*' + branch: '{branch}' + submodule-recursive: '{submodule-recursive}' + submodule-timeout: '{submodule-timeout}' + choosing-strategy: default + jenkins-ssh-credential: '{jenkins-ssh-credential}' + + triggers: + - timed: '{obj:cron}' + - github-pull-request: + trigger-phrase: '^build release$' + only-trigger-phrase: true + status-context: 'Maven Release' + permit-all: true + github-hooks: true + white-list-target-branches: + - '{branch}' + ############### # Maven Sonar # ############### @@ -1180,6 +1398,101 @@ - '{branch}' included-regions: '{obj:github_included_regions}' +########################### +# Maven Verify for Docker # +########################### + +- lf_maven_docker_verify: &lf_maven_docker_verify + name: lf-maven-docker-verify + + builders: + - lf-infra-pre-build + - lf-jacoco-nojava-workaround + - lf-maven-install: + mvn-version: '{mvn-version}' + - lf-update-java-alternatives: + java-version: '{java-version}' + - lf-infra-docker-login: + global-settings-file: '{mvn-global-settings}' + settings-file: '{mvn-settings}' + # must provide maven settings AFTER docker due to its cleanup + - lf-provide-maven-settings: + global-settings-file: '{mvn-global-settings}' + settings-file: '{mvn-settings}' + - inject: + properties-content: | + CONTAINER_PULL_REGISTRY={container-public-registry} + - lf-maven-build: + mvn-goals: '{mvn-goals}' + - lf-provide-maven-settings-cleanup + +- job-template: + name: '{project-name}-maven-docker-verify-{stream}-{mvn-version}-{java-version}' + id: gerrit-maven-docker-verify + <<: *lf_maven_common + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_verify + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_docker_verify + + scm: + - lf-infra-gerrit-scm: + jenkins-ssh-credential: '{jenkins-ssh-credential}' + git-url: '{git-url}' + refspec: '$GERRIT_REFSPEC' + branch: '$GERRIT_BRANCH' + submodule-recursive: '{submodule-recursive}' + submodule-timeout: '{submodule-timeout}' + choosing-strategy: gerrit + + triggers: + - gerrit: + server-name: '{gerrit-server-name}' + trigger-on: '{obj:gerrit_verify_triggers}' + projects: + - project-compare-type: ANT + project-pattern: '{project}' + branches: + - branch-compare-type: ANT + branch-pattern: '**/{branch}' + file-paths: '{obj:gerrit_trigger_file_paths}' + +- job-template: + name: '{project-name}-maven-docker-verify-{stream}-{mvn-version}-{java-version}' + id: github-maven-docker-verify + <<: *lf_maven_common + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_verify + # yamllint disable-line rule:key-duplicates + <<: *lf_maven_docker_verify + + properties: + - lf-infra-properties: + build-days-to-keep: '{build-days-to-keep}' + - github: + url: '{github-url}/{github-org}/{project}' + + scm: + - lf-infra-github-scm: + url: '{git-clone-url}{github-org}/{project}' + refspec: '+refs/pull/*:refs/remotes/origin/pr/*' + branch: '$sha1' + submodule-recursive: '{submodule-recursive}' + submodule-timeout: '{submodule-timeout}' + choosing-strategy: default + jenkins-ssh-credential: '{jenkins-ssh-credential}' + + triggers: + - github-pull-request: + trigger-phrase: '^(recheck|reverify)$' + only-trigger-phrase: false + status-context: 'Maven Docker Verify' + permit-all: true + github-hooks: true + white-list-target-branches: + - '{branch}' + included-regions: '{obj:github_included_regions}' + ############################# # Maven Verify Dependencies # ############################# diff --git a/releasenotes/notes/add-maven-docker-templates-6a515a99e5442dc2.yaml b/releasenotes/notes/add-maven-docker-templates-6a515a99e5442dc2.yaml new file mode 100644 index 00000000..f33ac4f0 --- /dev/null +++ b/releasenotes/notes/add-maven-docker-templates-6a515a99e5442dc2.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add verify, merge and stage templates for Java projects that build and + wrap a JAR (e.g., a Spring-Boot application) inside a Docker image, + and do not need to deploy any JAR libraries or POM files. -- 2.16.6