mirror of
https://github.com/google/nomulus.git
synced 2025-04-29 19:47:51 +02:00
Add a Gradle task to deploy the proxy (#214)
Also refactored some common code regarding the mapping between environments and projects. The script to update proxy deployments and kill all pods are lifted from https://cs.corp.google.com/piper///depot/google3/domain/registry/tools/bashrc?l=163
This commit is contained in:
parent
2a381b7071
commit
8240dee691
5 changed files with 105 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
37
projects.gradle
Normal file
37
projects.gradle
Normal file
|
@ -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)
|
|
@ -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 {
|
||||
|
|
44
proxy/deploy-proxy-for-env.sh
Executable file
44
proxy/deploy-proxy-for-env.sh
Executable file
|
@ -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"
|
Loading…
Add table
Reference in a new issue