From f96da3cb2901e97f3eb15434d39041f8cb1853ff Mon Sep 17 00:00:00 2001 From: jianglai Date: Fri, 14 Dec 2018 08:14:24 -0800 Subject: [PATCH] Add a cloud build config to upload WAR files to GCS The private repo structure is re-done to mirror that of the public repo to facilitate easy merging. Also removed steps to tag the private repos. This will likely cause a race condition if both the nomulus and the proxy cloud build are triggered by the same tag. They will both try to tag the private repo with the same tag. The tagging of the private repo should happen simultaneously with the public repo tagging, and in an out-of-band process as far as the build process is concerned. The build process should not have side effect on its source. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=225544063 --- cloudbuild-nomulus.yaml | 52 ++++++++++++++++++++++++ cloudbuild.yaml => cloudbuild-proxy.yaml | 23 ++++------- gradle/build.gradle | 2 +- 3 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 cloudbuild-nomulus.yaml rename cloudbuild.yaml => cloudbuild-proxy.yaml (57%) diff --git a/cloudbuild-nomulus.yaml b/cloudbuild-nomulus.yaml new file mode 100644 index 000000000..3b1e179a8 --- /dev/null +++ b/cloudbuild-nomulus.yaml @@ -0,0 +1,52 @@ +# To run the build locally, install cloud-build-local first. +# See: https://cloud.google.com/cloud-build/docs/build-debug-locally +# Then run: +# cloud-build-local --config=cloudbuild-nomulus.yaml --dryrun=false --substitutions TAG_NAME=[TAG] . +# This will create a docker image named gcr.io/[PROJECT_ID]/proxy:[TAG] locally. +# The PROJECT_ID is the current project name that gcloud uses. +# You can add "--push true" to have the image pushed to GCR. +# +# To manually trigger a build on GCB, run: +# gcloud builds submit --config cloudbuild-nomulus.yaml --substitutions TAG_NAME=[TAG] . +# +# To trigger a build automatically, follow the instructions below and add a trigger: +# https://cloud.google.com/cloud-build/docs/running-builds/automate-builds +steps: +# Set permissions correctly. Not sure why it is necessary, but it is. +- name: 'alpine' + args: ['chown', '-R', 'root:root', '.'] +- name: 'alpine' + args: ['chmod', '-R', '777', '.'] +# Clone the private repo and merge its contents. +- name: 'gcr.io/cloud-builders/gcloud' + args: ['source', 'repos', 'clone', 'nomulus-config'] +- name: 'alpine' + args: ['sh', '-c', 'cp -r nomulus-config/* .'] +# Build the war files. +- name: 'openjdk:8-slim' + args: ['./gradlew', 'stage', '-x', 'autoLintGradle'] + dir: 'gradle' +- name: 'openjdk:8-slim' + args: ['jar', '-cvf', '../../../default-${TAG_NAME}.war', '.'] + dir: 'gradle/services/default/build/exploded-default' +- name: 'openjdk:8-slim' + args: ['jar', '-cvf', '../../../pubapi-${TAG_NAME}.war', '.'] + dir: 'gradle/services/pubapi/build/exploded-pubapi' +- name: 'openjdk:8-slim' + args: ['jar', '-cvf', '../../../backend-${TAG_NAME}.war', '.'] + dir: 'gradle/services/backend/build/exploded-backend' +- name: 'openjdk:8-slim' + args: ['jar', '-cvf', '../../../tools-${TAG_NAME}.war', '.'] + dir: 'gradle/services/tools/build/exploded-tools' +# WAR files to upload to GCS. +artifacts: + objects: + location: 'gs://${PROJECT_ID}-war' + paths: + - 'gradle/services/default-${TAG_NAME}.war' + - 'gradle/services/pubapi-${TAG_NAME}.war' + - 'gradle/services/backend-${TAG_NAME}.war' + - 'gradle/services/tools-${TAG_NAME}.war' +timeout: 3600s +options: + machineType: 'N1_HIGHCPU_8' diff --git a/cloudbuild.yaml b/cloudbuild-proxy.yaml similarity index 57% rename from cloudbuild.yaml rename to cloudbuild-proxy.yaml index 773d7e9e6..a95c87d3d 100644 --- a/cloudbuild.yaml +++ b/cloudbuild-proxy.yaml @@ -1,15 +1,15 @@ # To run the build locally, install cloud-build-local first. # See: https://cloud.google.com/cloud-build/docs/build-debug-locally # Then run: -# cloud-build-local --config=cloudbuild.yaml --dryrun=false --substitutions TAG_NAME=[TAG] . +# cloud-build-local --config=cloudbuild-proxy.yaml --dryrun=false --substitutions TAG_NAME=[TAG] . # This will create a docker image named gcr.io/[PROJECT_ID]/proxy:[TAG] locally. # The PROJECT_ID is the current project name that gcloud uses. # You can add "--push true" to have the image pushed to GCR. # # To manually trigger a build on GCB, run: -# gcloud builds submit --config cloudbuild.yaml --substitutions TAG_NAME=[TAG] . +# gcloud builds submit --config cloudbuild-proxy.yaml --substitutions TAG_NAME=[TAG] . # -# To trigger a build automatically, follow the instructions below and add a tigger: +# To trigger a build automatically, follow the instructions below and add a trigger: # https://cloud.google.com/cloud-build/docs/running-builds/automate-builds steps: # Set permissions correctly. Not sure why it is necessary, but it is. @@ -17,28 +17,21 @@ steps: args: ['chown', '-R', 'root:root', '.'] - name: 'alpine' args: ['chmod', '-R', '777', '.'] -# Clone the private repo, tag it, and copy its contents to the correct place. +# Clone the private repo merge its contents. - name: 'gcr.io/cloud-builders/gcloud' args: ['source', 'repos', 'clone', 'nomulus-config'] -- name: 'gcr.io/cloud-builders/git' - args: ['tag', '$TAG_NAME'] - dir: 'nomulus-config' - name: 'alpine' - args: ['sh', '-c', 'cp -r nomulus-config/proxy/* java/google/registry/proxy/config/'] + args: ['sh', '-c', 'cp -r nomulus-config/* .'] # Build the deploy jar. - name: 'openjdk:8-slim' - args: ['./gradlew', 'testClasses', ':proxy:deployJar'] + args: ['./gradlew', ':proxy:deployJar', '-x', 'autoLintGradle'] dir: 'gradle' # Build the docker image. - name: 'gcr.io/cloud-builders/docker' - args: ['build', '--tag', 'gcr.io/$PROJECT_ID/proxy:$TAG_NAME', '.'] + args: ['build', '--tag', 'gcr.io/${PROJECT_ID}/proxy:${TAG_NAME}', '.'] dir: 'gradle/proxy' -# Push the tag to the private repo after a successful build. -- name: 'gcr.io/cloud-builders/git' - args: ['push', 'origin', '$TAG_NAME'] - dir: 'nomulus-config' # Images to upload to GCR. -images: ['gcr.io/$PROJECT_ID/proxy:$TAG_NAME'] +images: ['gcr.io/${PROJECT_ID}/proxy:${TAG_NAME}'] timeout: 3600s options: machineType: 'N1_HIGHCPU_8' diff --git a/gradle/build.gradle b/gradle/build.gradle index b975c28e5..1a39540b9 100644 --- a/gradle/build.gradle +++ b/gradle/build.gradle @@ -84,7 +84,7 @@ subprojects { } rootProject.deploy.dependsOn appengineDeploy - rootProject.stage.dependsOn appengineStage + rootProject.stage.dependsOn explodeWar // Return early, do not apply the settings below. return