diff --git a/appengine_war.gradle b/appengine_war.gradle index 1a1a8b76b..4a8214c36 100644 --- a/appengine_war.gradle +++ b/appengine_war.gradle @@ -12,25 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -def environments = ['production', 'sandbox', 'alpha', 'crash'] - -def projects = ['production': 'domain-registry', - 'sandbox' : 'domain-registry-sandbox', - 'alpha' : 'domain-registry-alpha', - 'crash' : 'domain-registry-crash'] - - -def environment = rootProject.findProperty("environment") -if (environment == null) { - environment = 'production' -} -def gcpProject = projects[environment] -if (gcpProject == null) { - throw new GradleException("-Penvironment must be one of ${environments}.") -} - +apply from: "${rootDir.path}/projects.gradle" apply plugin: 'war' +def environment = rootProject.environment +def gcpProject = rootProject.gcpProject + // Set this directory before applying the appengine plugin so that the // plugin will recognize this as an app-engine standard app (and also // obtains the appengine-web.xml from the correct location) @@ -77,8 +64,8 @@ appengine { deploy { // appengineDeployAll task requires the version to be set. So, // this config lets gcloud select a version name when deploying - // to alpha from our workstation. - if (environment != 'production' && environment != 'sandbox') { + // to alpha or sandbox from our workstation. + if (!rootProject.prodOrSandboxEnv) { version = 'GCLOUD_CONFIG' } projectId = gcpProject @@ -91,4 +78,4 @@ dependencies { rootProject.deploy.dependsOn appengineDeployAll rootProject.stage.dependsOn appengineStage -appengineDeploy.dependsOn rootProject.verifyDeployment +appengineDeployAll.dependsOn rootProject.verifyDeployment diff --git a/build.gradle b/build.gradle index 5a756e662..2e09d5d59 100644 --- a/build.gradle +++ b/build.gradle @@ -109,10 +109,10 @@ task deploy { task verifyDeployment { group = 'deployment' - description = 'Ensure that one can only deploy to alpha.' + description = 'Ensure that one cannot deploy to production or sandbox.' doFirst { - if (rootProject.findProperty("environment") != 'alpha') { - throw new GradleException("Can only deploy to alpha."); + if (rootProject.prodOrSandboxEnv) { + throw new GradleException("Cannot deploy to production or sandbox."); } } } diff --git a/projects.gradle b/projects.gradle new file mode 100644 index 000000000..6b061fb82 --- /dev/null +++ b/projects.gradle @@ -0,0 +1,37 @@ +// 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. + +def environments = ['production', 'sandbox', 'alpha', 'crash'] + +def projects = ['production': 'domain-registry', + 'sandbox' : 'domain-registry-sandbox', + 'alpha' : 'domain-registry-alpha', + 'crash' : 'domain-registry-crash'] + + +def environment = rootProject.findProperty("environment") + +if (environment == null) { + environment = 'production' +} + +def gcpProject = projects[environment] + +if (gcpProject == null) { + throw new GradleException("-Penvironment must be one of ${environments}.") +} + +rootProject.ext.environment = environment +rootProject.ext.gcpProject = gcpProject +rootProject.ext.prodOrSandboxEnv = ['production', 'sandbox'].contains(environment) diff --git a/proxy/build.gradle b/proxy/build.gradle index d36a400cc..c545e8240 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -18,6 +18,20 @@ task buildProxyImage(dependsOn: deployJar, type: Exec) { commandLine 'docker', 'build', '-t', 'proxy', '.' } +task deployProxy(dependsOn: [buildProxyImage, ':verifyDeployment']) { + doLast { + exec { + commandLine 'docker', 'tag', 'proxy', "gcr.io/${rootProject.gcpProject}/proxy" + } + exec { + commandLine 'docker', 'push', "gcr.io/${rootProject.gcpProject}/proxy" + } + exec { + commandLine './deploy-proxy-for-env.sh', "${rootProject.environment}" + } + } +} + project.build.dependsOn buildProxyImage dependencies { diff --git a/proxy/deploy-proxy-for-env.sh b/proxy/deploy-proxy-for-env.sh new file mode 100755 index 000000000..8c584f8f3 --- /dev/null +++ b/proxy/deploy-proxy-for-env.sh @@ -0,0 +1,44 @@ +#!/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 builds the GAE artifacts for a given environment, moves the +# artifacts for all services to a designated location, and then creates a + +if [[ $# -ne 1 ]]; then + echo "Usage: $0 alpha|crash" + exit 1 +fi + +environment=${1} +project="domain-registry-"${environment} +current_context=$(kubectl config current-context) +while read line +do + parts=(${line}) + echo "Updating cluster ${parts[0]} in zone ${parts[1]}..." + gcloud container clusters get-credentials "${parts[0]}" \ + --project "${project}" --zone "${parts[1]}" + # Kills all running pods, new pods created will be pulling the new image. + sed s/GCP_PROJECT/${project}/g "./kubernetes/proxy-deployment-${environment}.yaml" | \ + kubectl replace -f - + # Alpha does not have canary + if [[ ${environment} != "alpha" ]] + then + sed s/GCP_PROJECT/${project}/g "./kubernetes/proxy-deployment-${environment}-canary.yaml" | \ + kubectl replace -f - + fi + kubectl delete pods --all +done < <(gcloud container clusters list --project ${project} | grep proxy-cluster) +kubectl config use-context "$current_context"