mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 12:07:51 +02:00
Improve error handling for environment property (#295)
* Improve error handling for environment property Improve the error messages that we get for a bad or missing environment property. Move the property processing into the main build so that we do it only once and configure all of the appengine deployment tasks to check that a project has been defined and print a friendly error if it hasn't. Note that even if the check isn't configured, this change prevents deployment because the gcpProject will be set to null. It just won't print as useful an error message. Tested: ran appengineDeployAll with and without the environment property, ran "build" to verify that we don't get any complaints for non-deployment targets. * Changes for review. * Changes for review * Changes for review. * Changes for review.
This commit is contained in:
parent
430cd109f9
commit
98a83eb490
4 changed files with 72 additions and 49 deletions
|
@ -12,7 +12,6 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
apply from: "${rootDir.path}/projects.gradle"
|
|
||||||
apply plugin: 'war'
|
apply plugin: 'war'
|
||||||
|
|
||||||
def environment = rootProject.environment
|
def environment = rootProject.environment
|
||||||
|
@ -68,6 +67,10 @@ appengine {
|
||||||
if (!rootProject.prodOrSandboxEnv) {
|
if (!rootProject.prodOrSandboxEnv) {
|
||||||
version = 'GCLOUD_CONFIG'
|
version = 'GCLOUD_CONFIG'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't set gcpProject directly, it gets overriden in ./build.gradle.
|
||||||
|
// Do -P environment={crash,alpha} instead. For sandbox/production,
|
||||||
|
// use Spinnaker.
|
||||||
projectId = gcpProject
|
projectId = gcpProject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,4 +95,15 @@ explodeWar.doLast {
|
||||||
|
|
||||||
rootProject.deploy.dependsOn appengineDeployAll
|
rootProject.deploy.dependsOn appengineDeployAll
|
||||||
rootProject.stage.dependsOn appengineStage
|
rootProject.stage.dependsOn appengineStage
|
||||||
appengineDeployAll.dependsOn rootProject.verifyDeployment
|
|
||||||
|
// Impose verification for all of the deployment tasks. We haven't found a
|
||||||
|
// better way to do this other than to apply to each of them independently.
|
||||||
|
// If a new task gets added, it will still fail if "environment" is not defined
|
||||||
|
// because gcpProject is null. We just won't get as friendly an error message.
|
||||||
|
appengineDeployAll.configure rootProject.verifyDeploymentConfig
|
||||||
|
appengineDeploy.configure rootProject.verifyDeploymentConfig
|
||||||
|
appengineDeployCron.configure rootProject.verifyDeploymentConfig
|
||||||
|
appengineDeployDispatch.configure rootProject.verifyDeploymentConfig
|
||||||
|
appengineDeployDos.configure rootProject.verifyDeploymentConfig
|
||||||
|
appengineDeployIndex.configure rootProject.verifyDeploymentConfig
|
||||||
|
appengineDeployQueue.configure rootProject.verifyDeploymentConfig
|
||||||
|
|
63
build.gradle
63
build.gradle
|
@ -109,21 +109,64 @@ task deploy {
|
||||||
description = 'Deploys all services to App Engine.'
|
description = 'Deploys all services to App Engine.'
|
||||||
}
|
}
|
||||||
|
|
||||||
task verifyDeployment {
|
|
||||||
group = 'deployment'
|
|
||||||
description = 'Ensure that one cannot deploy to production or sandbox.'
|
|
||||||
doFirst {
|
|
||||||
if (rootProject.prodOrSandboxEnv) {
|
|
||||||
throw new GradleException("Cannot deploy to production or sandbox.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task stage {
|
task stage {
|
||||||
group = 'deployment'
|
group = 'deployment'
|
||||||
description = 'Generates application directories for all services.'
|
description = 'Generates application directories for all services.'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// App-engine environment configuration. We set up all of the variables in
|
||||||
|
// the root project.
|
||||||
|
|
||||||
|
def environments = ['production', 'sandbox', 'alpha', 'crash']
|
||||||
|
|
||||||
|
// TODO(mmuller): Move this into internal specialization code.
|
||||||
|
def projects = ['production': 'domain-registry',
|
||||||
|
'sandbox' : 'domain-registry-sandbox',
|
||||||
|
'alpha' : 'domain-registry-alpha',
|
||||||
|
'crash' : 'domain-registry-crash']
|
||||||
|
|
||||||
|
def gcpProject = null
|
||||||
|
|
||||||
|
if (environment == '') {
|
||||||
|
// Keep the project null, this will prevent deployment. Set the
|
||||||
|
// environment to "alpha" because other code needs this property to
|
||||||
|
// explode the war file.
|
||||||
|
environment = 'alpha'
|
||||||
|
} else if (environment != 'production' && environment != 'sandbox') {
|
||||||
|
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 = environment in ['production', 'sandbox']
|
||||||
|
|
||||||
|
// Function to verify that the deployment parameters have been set.
|
||||||
|
def verifyDeploymentParams() {
|
||||||
|
if (prodOrSandboxEnv) {
|
||||||
|
// Do not deploy to prod or sandbox. Print a prominent error in bright red.
|
||||||
|
System.err.println('\033[31;1m-----------------------------------------------------------------')
|
||||||
|
System.err.println('*** DANGER WILL ROBINSON!')
|
||||||
|
System.err.println('*** You may not deploy to production or sandbox from gradle. Do a')
|
||||||
|
System.err.println('*** release from Spinnaker, see deployment playbook.')
|
||||||
|
System.err.println('-----------------------------------------------------------------')
|
||||||
|
throw new GradleException('Aborting. See prominent error above.')
|
||||||
|
} else if (gcpProject == null) {
|
||||||
|
def error = 'You must specify -P environment={alpha,crash}'
|
||||||
|
System.err.println("\033[33;1m${error}\033[0m")
|
||||||
|
throw GradleException("Aborting: ${error}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Closure that we can just drop into all of our deployment tasks.
|
||||||
|
rootProject.ext.verifyDeploymentConfig = {
|
||||||
|
doFirst { verifyDeploymentParams() }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subproject configuration.
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
// Skip no-op project
|
// Skip no-op project
|
||||||
if (project.name == 'services') return
|
if (project.name == 'services') return
|
||||||
|
|
|
@ -8,6 +8,9 @@ verboseTestOutput=false
|
||||||
flowDocsFile=
|
flowDocsFile=
|
||||||
enableDependencyLocking=true
|
enableDependencyLocking=true
|
||||||
|
|
||||||
|
# GAE Environment for deployment and staging.
|
||||||
|
environment=
|
||||||
|
|
||||||
# Cloud SQL properties
|
# Cloud SQL properties
|
||||||
|
|
||||||
# A registry environment name (e.g., 'alpha') or a host[:port] string
|
# A registry environment name (e.g., 'alpha') or a host[:port] string
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
// 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)
|
|
Loading…
Add table
Reference in a new issue