google-nomulus/jetty/build.gradle
Lai Jiang 1fb27fcf8e
Make nomulus work locally (#2349)
Chose the default transaction manager based on RegistryEnvironment. This
makes it possible to run nomulus on Jetty locally. Tested with the
following:

```bash
./gradle :jetty:run -Penvironment=alpha
curl http://localhost:8080/beta.app
```

The docker image is also updated to take an argument that specifies the
environment. It runs locally as well but the container doesn't get
access to locally stored credentials, so it fails to initialize the
transaction manager.
2024-03-11 16:05:44 +00:00

69 lines
2.2 KiB
Groovy

// Copyright 2024 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.
apply plugin: 'war'
tasks.register('copyJettyBase', Copy) {
from(layout.projectDirectory.dir('src/main')) {
include 'jetty-base/**'
}
into layout.buildDirectory
}
war {
setArchiveBaseName("nomulus")
setDestinationDirectory(layout.buildDirectory.dir('jetty-base/webapps'))
dependsOn(tasks.named('copyJettyBase'))
}
dependencies {
implementation project(':core')
}
tasks.register('copyConsole', Copy) {
from("${rootDir}/console-webapp/dist/console-webapp") {
include "**/*"
}
into layout.buildDirectory.dir('jetty-base/webapps/console')
dependsOn(':console-webapp:buildConsoleWebappProd')
}
tasks.register('stage') {
dependsOn(tasks.named('war'))
dependsOn(tasks.named('copyConsole'))
}
tasks.register('buildNomulusImage', Exec) {
commandLine 'docker', 'build', '-t', 'nomulus', '.'
dependsOn(tasks.named('stage'))
}
tasks.register('run', JavaExec) {
// We do the check when the task actually runs, not when we define it.
// This way if one doesn't set the value, one can still run other tasks.
doFirst {
def jetty_home = System.getenv('JETTY_HOME')
if (jetty_home == null) {
throw new GradleException('JETTY_HOME is not set.')
}
}
def jetty_home = System.getenv('JETTY_HOME')
def environment = rootProject.environment
workingDir(layout.buildDirectory.dir('jetty-base'))
classpath = files(jetty_home + '/start.jar')
systemProperty('google.registry.environment', environment)
dependsOn(tasks.named('stage'))
}
project.build.dependsOn(tasks.named('buildNomulusImage'))