From 5bd2ccd2107c89a40d665b96deff4cd43c721bf2 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Thu, 18 Jul 2019 12:15:15 -0400 Subject: [PATCH] Add a Cloud Build task to update YAML configs (#177) * Add a Cloud Build task to update YAML configs * CR responses * Move config deployment to a script * Pin builder version * Create different beam and deploy-config files per environment * Update comments and make a for loop --- release/cloudbuild-deploy-configs.yaml | 22 +++++++++++++ release/cloudbuild-nomulus.yaml | 4 ++- release/cloudbuild-release.yaml | 7 +++- release/deploy_configs_to_env.sh | 45 ++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 release/cloudbuild-deploy-configs.yaml create mode 100755 release/deploy_configs_to_env.sh diff --git a/release/cloudbuild-deploy-configs.yaml b/release/cloudbuild-deploy-configs.yaml new file mode 100644 index 000000000..2438e1cc4 --- /dev/null +++ b/release/cloudbuild-deploy-configs.yaml @@ -0,0 +1,22 @@ +# To run the build locally, install cloud-build-local first. +# See: https://cloud.google.com/cloud-build/docs/build-debug-locally +# You will need access to a private registry, so be sure to install the docker +# credential helper. +# Then, in the release folder, run: +# cloud-build-local --config=cloudbuild-deploy-configs.yaml --dryrun=false \ +# --substitutions TAG_NAME=[TAG],_ENV=[ENV] .. +# This will build the contents of the current directory and generate the +# nomulus war-files 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-deploy-configs.yaml \ +# --substitutions TAG_NAME=[TAG],_ENV=[ENV] .. +# +# 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: +# Download and unzip the tarball that contains the relevant config files +- name: 'gcr.io/${PROJECT_ID}/builder:latest' + args: ['release/deploy_configs_to_env.sh', '${_ENV}', '${TAG_NAME}'] diff --git a/release/cloudbuild-nomulus.yaml b/release/cloudbuild-nomulus.yaml index 90ad73cca..04bfdd0d3 100644 --- a/release/cloudbuild-nomulus.yaml +++ b/release/cloudbuild-nomulus.yaml @@ -64,7 +64,9 @@ artifacts: - 'output/nomulus.jar' - 'release/cloudbuild-tag.yaml' - 'release/cloudbuild-sync.yaml' - - 'release/cloudbuild-beam.yaml' + - 'release/cloudbuild-beam-*.yaml' + - 'release/cloudbuild-deploy-configs-*.yaml' + timeout: 3600s options: machineType: 'N1_HIGHCPU_8' diff --git a/release/cloudbuild-release.yaml b/release/cloudbuild-release.yaml index ba9e39f7d..9d0e1cd98 100644 --- a/release/cloudbuild-release.yaml +++ b/release/cloudbuild-release.yaml @@ -84,12 +84,17 @@ steps: sed -i s/builder:latest/builder@$builder_digest/g release/cloudbuild-proxy.yaml sed -i s/builder:latest/builder@$builder_digest/g release/cloudbuild-nomulus.yaml sed -i s/builder:latest/builder@$builder_digest/g release/cloudbuild-beam.yaml + sed -i s/builder:latest/builder@$builder_digest/g release/cloudbuild-deploy-configs.yaml sed -i s/builder:latest/builder@$builder_digest/g release/cloudbuild-sync.yaml sed -i s/builder:latest/builder@$builder_digest/g release/cloudbuild-tag.yaml sed -i s/GCP_PROJECT/${PROJECT_ID}/ proxy/kubernetes/proxy-*.yaml sed -i s/'$${TAG_NAME}'/${TAG_NAME}/g release/cloudbuild-sync.yaml sed -i s/'$${TAG_NAME}'/${TAG_NAME}/g release/cloudbuild-beam.yaml - sed -i s/'$${_ENV}'/${_ENV}/g release/cloudbuild-beam.yaml + sed -i s/'$${TAG_NAME}'/${TAG_NAME}/g release/cloudbuild-deploy-configs.yaml + for environment in alpha crash sandbox production; do + sed s/'$${_ENV}'/${environment}/g release/cloudbuild-beam.yaml > release/cloudbuild-beam-${environment}.yaml + sed s/'$${_ENV}'/${environment}/g release/cloudbuild-deploy-configs.yaml > release/cloudbuild-deploy-configs-${environment}.yaml + done # Upload the gradle binary to GCS if it does not exist and point URL in gradle wrapper to it. - name: 'gcr.io/cloud-builders/gsutil' entrypoint: /bin/bash diff --git a/release/deploy_configs_to_env.sh b/release/deploy_configs_to_env.sh new file mode 100755 index 000000000..d67e2077d --- /dev/null +++ b/release/deploy_configs_to_env.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Copyright 2019 The Nomulus Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This script downloads the tagged tarball from GCS and uploads the AppEngine config files therein +# to the provided environment. The standard AppEngine deployment process doesn't automatically +# update these configs, so we must do it manually. + +set -e + +if [ $# -ne 2 ]; +then + echo "Usage: $0 alpha|crash|sandbox|production " + exit 1 +fi + +environment="$1" +tag_name="$2" + +if [ "${environment}" == alpha ]; then + project_id="domain-registry-alpha" +elif [ "${environment}" == crash ]; then + project_id="domain-registry-crash" +elif [ "${environment}" == sandbox ]; then + project_id="domain-registry-sandbox" +elif [ "${environment}" == production ]; then + project_id="domain-registry" +fi + +gsutil cp gs://domain-registry-dev-deploy/${tag_name}/${environment}.tar . +tar -xvf ${environment}.tar +for filename in cron dispatch dos index queue; do + gcloud -q --project ${project_id} app deploy default/WEB-INF/appengine-generated/${filename}.yaml +done