Skip to content

Commit fd51035

Browse files
authored
Stop depending on GCS public access for Kokoro (#2907)
We used to publish test artifacts to a Maven repo on GCS, for use by schema tests. For this to work with Kokoro, the GCS bucket must be accessible to all users. To comply with the no-public-user requirement, we store the necessary jars at at well-known bucket and map them into Kokoro. This strategy cannot be used on the Maven repo because only a small number of files with fixed names may be mapped. With the Maven repo, there are too many files to map.
1 parent 90eb078 commit fd51035

File tree

9 files changed

+99
-163
lines changed

9 files changed

+99
-163
lines changed

config/nom_build.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,19 @@ class GradleFlag:
117117
Property('dbUser', 'Database user name for use in connection'),
118118
Property('dbPassword', 'Database password for use in connection'),
119119

120-
Property('publish_repo',
121-
'Maven repository that hosts the Cloud SQL schema jar and the '
122-
'registry server test jars. Such jars are needed for '
123-
'server/schema integration tests. Please refer to <a '
124-
'href="./integration/README.md">integration project</a> for more '
125-
'information.'),
126-
Property('baseSchemaTag',
127-
'The nomulus version tag of the schema for use in the schema'
128-
'deployment integration test (:db:schemaIncrementalDeployTest)'),
129-
Property('schema_version',
130-
'The nomulus version tag of the schema for use in a database'
131-
'integration test.'),
132-
Property('nomulus_version',
133-
'The version of nomulus to test against in a database '
134-
'integration test.'),
135120
Property('dot_path',
136121
'The path to "dot", part of the graphviz package that converts '
137122
'a BEAM pipeline to image. Setting this property to empty string '
138123
'will disable image generation.',
139124
'/usr/bin/dot'),
140125
Property('pipeline',
141-
'The name of the Beam pipeline being staged.')
126+
'The name of the Beam pipeline being staged.'),
127+
Property('nomulus_env',
128+
'For use by scripts. Normally not set manually.'),
129+
Property('schema_env',
130+
'For use by scripts. Normally not set manually.'),
131+
Property('schemaTestArtifactsDir',
132+
'For use by scripts. Normally not set manually.')
142133
]
143134

144135
GRADLE_FLAGS = [

core/build.gradle

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -646,23 +646,6 @@ artifacts {
646646
nomulus_test testUberJar
647647
}
648648

649-
publishing {
650-
repositories {
651-
maven {
652-
url project.publish_repo
653-
}
654-
}
655-
publications {
656-
nomulusTestsPublication(MavenPublication) {
657-
groupId 'google.registry'
658-
artifactId 'nomulus_test'
659-
version project.nomulus_version
660-
artifact nomulusFossJar
661-
artifact testUberJar
662-
}
663-
}
664-
}
665-
666649
task buildToolImage(dependsOn: nomulus, type: Exec) {
667650
commandLine 'docker', 'build', '-t', 'nomulus-tool', '.'
668651
}

db/build.gradle

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,6 @@ artifacts {
126126
schema schemaJar
127127
}
128128

129-
publishing {
130-
repositories {
131-
maven {
132-
url project.publish_repo
133-
}
134-
}
135-
publications {
136-
sqlSchemaPublication(MavenPublication) {
137-
groupId 'google.registry'
138-
artifactId 'schema'
139-
version project.schema_version
140-
artifact schemaJar
141-
}
142-
}
143-
}
144-
145129
// Adds flyway tasks such as: flywayInfo, flywayValidate, flywayMigrate (
146130
// deploying the schema in local repository), and flywayClean (dropping all data
147131
// in the database). The latter two commands are disallowed in environments
@@ -248,14 +232,10 @@ if (ext.isRestricted()) {
248232
}
249233
}
250234

251-
if (project.baseSchemaTag != '') {
252-
repositories {
253-
maven {
254-
url project.publish_repo
255-
}
256-
}
235+
if (project.schemaTestArtifactsDir != '') {
257236
dependencies {
258-
integration "google.registry:schema:${project.baseSchemaTag}"
237+
// For schemaIncrementalDeployTest, which only uses sandbox schema
238+
integration files("${project.schemaTestArtifactsDir}/schema.sandbox.jar")
259239
}
260240

261241
// Checks if Flyway scripts can be deployed to an existing database with

gradle.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ dbServer=
2222
dbName=postgres
2323
dbUser=
2424
dbPassword=
25-
publish_repo=
26-
baseSchemaTag=
27-
schema_version=
28-
nomulus_version=
2925
dot_path=/usr/bin/dot
3026
pipeline=
27+
nomulus_env=
28+
schema_env=
29+
schemaTestArtifactsDir=

integration/README.md

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,38 @@
11
## Summary
22

3-
This project runs cross-version server/schema integration tests with arbitrary
4-
version pairs. It may be used by presubmit tests and continuous-integration
5-
tests, or as a gating test during release and/or deployment.
3+
This subproject provides two integration tests that ensure schema safety:
64

7-
## Maven Dependencies
5+
* One test checks for edits to Flyway scripts already deployed to Sandbox
6+
Production. Such edits will cause schema deployment failure.
7+
* Another test runs cross-version server/schema integration tests between a
8+
pull request and the deployed release in Sandbox or Production. If a pull
9+
request fails this test, it either contains schema changes not compatible
10+
with Sandbox/Production binaries, or binaries not compatible with the
11+
current schema in Sandbox/Production. This test may be include in presubmit
12+
testing.
813

9-
This release process is expected to publish the following Maven dependencies to
10-
a well-known repository:
14+
## Test Artifacts
1115

12-
* google.registry:schema, which contains the schema DDL scripts. This is done
13-
by the ':db:publish' task.
14-
* google.registry:nomulus_test, which contains the nomulus classes and
15-
dependencies needed for the integration tests. This is done by the
16-
':core:publish' task.
16+
To support the tests above, each release generates the following test artifacts:
1717

18-
After each deployment in sandbox or production, the deployment process is
19-
expected to save the version tag of the binary or schema along with the
20-
environment. These tags will be made available to test runners.
18+
* schema.jar: The flyway scripts.
19+
* nomulus-public.jar: The open-source java classes.
20+
* nomulus-tests-alldeps.jar: Uber jar with schema test classes and all
21+
third-party dependencies.
2122

22-
## Usage
23+
After each deployment in sandbox or production, the deployment process copies
24+
these artifacts to a well-known location, and appends the environment tag to
25+
the file names.
2326

24-
The ':integration:sqlIntegrationTest' task is the test runner. It uses the
25-
following properties:
27+
## Usage
2628

27-
* nomulus_version: a Registry server release tag, or 'local' if the code in
28-
the local Git tree should be used.
29-
* schema_version: a schema release tag, or 'local' if the code in the local
30-
Git tree should be used.
31-
* publish_repo: the Maven repository where release jars may be found. This is
32-
required if neither of the above is 'local'.
29+
Use the convenience scripts in the `integration` folder to run the tests.
3330

34-
Given a program 'fetch_version_tag' that retrieves the currently deployed
35-
version tag of SQL schema or server binary in a particular environment (which as
36-
mentioned earlier are saved by the deployment process), the following code
37-
snippet checks if the current PR or local clone has schema changes, and if yes,
38-
tests the production server's version with the new schema.
31+
```bash
32+
./integration/run_schema_check.sh -p domain-registry-dev
3933

40-
```shell
41-
current_prod_schema=$(fetch_version_tag schema production)
42-
current_prod_server=$(fetch_version_tag server production)
43-
schema_changes=$(git diff ${current_prod_schema} --name-only \
44-
./db/src/main/resources/sql/flyway/ | wc -l)
45-
[[ schema_changes -gt 0 ]] && ./gradlew :integration:sqlIntegrationTest \
46-
-Ppublish_repo=${REPO} -Pschema_version=local \
47-
-Pnomulus_version=current_prod_server
34+
./integration/run_compatibility_tests.sh -p domain-registry-dev -s sql
35+
./integration/run_compatibility_tests.sh -p domain-registry-dev -s nomulus
4836
```
4937

5038
## Implementation Notes

integration/build.gradle

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,42 @@
1818
import static com.google.common.base.Preconditions.checkArgument
1919
import static com.google.common.base.Strings.isNullOrEmpty
2020

21-
if (schema_version == '' || nomulus_version == '') {
21+
if (schema_env == '' || nomulus_env == '') {
2222
return
2323
}
2424

2525
def USE_LOCAL = 'local'
2626

27-
if (schema_version != USE_LOCAL || nomulus_version != USE_LOCAL) {
27+
if (schema_env != USE_LOCAL || nomulus_env != USE_LOCAL) {
2828
checkArgument(
29-
!isNullOrEmpty(publish_repo),
30-
'The publish_repo is required when remote jars are needed.')
31-
32-
repositories {
33-
maven {
34-
url project.publish_repo
35-
}
36-
}
29+
!isNullOrEmpty(schemaTestArtifactsDir),
30+
'The schemaTestArtifactsDir is required when deployed jars are needed.')
3731
}
3832

3933
def testUberJarName = ''
4034

4135
// Might need to add this back if we re-add nebula-lint
4236
// gradleLint.ignore('unused-dependency') {
4337
dependencies {
44-
if (schema_version == USE_LOCAL) {
38+
if (schema_env == USE_LOCAL) {
4539
testRuntimeOnly project(path: ':db', configuration: 'schema')
4640
} else {
47-
testRuntimeOnly "google.registry:schema:${schema_version}"
41+
testRuntimeOnly files("${project.schemaTestArtifactsDir}/schema.${schema_env}.jar")
4842
}
49-
if (nomulus_version == USE_LOCAL) {
43+
if (nomulus_env == USE_LOCAL) {
5044
testRuntimeOnly project(path: ':core', configuration: 'nomulus_test')
5145
testUberJarName = 'nomulus-tests-alldeps.jar'
5246
} else {
53-
testRuntimeOnly "google.registry:nomulus_test:${nomulus_version}:public"
54-
testRuntimeOnly "google.registry:nomulus_test:${nomulus_version}:alldeps"
55-
testUberJarName = "nomulus_test-${nomulus_version}-alldeps.jar"
47+
testRuntimeOnly files("${project.schemaTestArtifactsDir}/nomulus-public.${nomulus_env}.jar")
48+
testRuntimeOnly files("${project.schemaTestArtifactsDir}/nomulus-tests-alldeps.${nomulus_env}.jar")
49+
testUberJarName = "nomulus-tests-alldeps.${nomulus_env}.jar"
5650
}
5751
}
5852
// }
5953

6054
configurations.testRuntimeOnly.transitive = false
6155

62-
def unpackedTestDir = "${projectDir}/build/unpackedTests/${nomulus_version}"
56+
def unpackedTestDir = "${projectDir}/build/unpackedTests/${nomulus_env}"
6357

6458
// Extracts SqlIntegrationTestSuite.class to a temp folder. Gradle's test
6559
// runner only looks for runnable tests on a regular file system. However,
@@ -78,7 +72,7 @@ task extractSqlIntegrationTestSuite (type: Copy) {
7872
into unpackedTestDir
7973
includeEmptyDirs = false
8074

81-
if (nomulus_version == USE_LOCAL) {
75+
if (nomulus_env == USE_LOCAL) {
8276
dependsOn ':core:testUberJar'
8377
}
8478
}

integration/run_compatibility_tests.sh

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,50 @@ function runTest() {
5656
local deployed_system=${1}
5757
local version=${2}
5858
local dev_project=${3}
59+
local env=${4}
5960

60-
local changes=$(getChangeCountSinceVersion ${deployed_system} ${version})
61-
if [[ ${changes} = 0 ]]; then
62-
echo "No relevant changes in ${deployed_system} since ${version}"
63-
return 0
64-
fi
61+
# local changes=$(getChangeCountSinceVersion ${deployed_system} ${version})
62+
# if [[ ${changes} = 0 ]]; then
63+
# echo "No relevant changes in ${deployed_system} since ${version}"
64+
# return 0
65+
# fi
66+
#
67+
# echo "Found relevant changes in ${deployed_system} since ${version}"
6568

66-
echo "Found relevant changes in ${deployed_system} since ${version}"
69+
if [[ -n "${SCHEMA_TEST_ARTIFACTS_DIR}" ]]; then
70+
echo "Using schema test jars downloaded to ${SCHEMA_TEST_ARTIFACTS_DIR}"
71+
else
72+
SCHEMA_TEST_ARTIFACTS_DIR=$(mktemp -d)
73+
echo "Created working dir ${SCHEMA_TEST_ARTIFACTS_DIR} for downloaded test jars."
74+
trap 'rm -rf ${SCHEMA_TEST_ARTIFACTS_DIR}' EXIT
75+
gcloud storage cp --verbosity=none \
76+
"gs://${DEV_PROJECT}-deployed-tags/schema-test-artifacts/*.jar" \
77+
"${SCHEMA_TEST_ARTIFACTS_DIR}"
78+
fi
6779

68-
local nomulus_version
69-
local schema_version
80+
local nomulus_env
81+
local schema_env
7082

7183
if [[ ${deployed_system} = "sql" ]]; then
72-
schema_version=${version}
73-
nomulus_version="local"
84+
schema_env=${env}
85+
nomulus_env="local"
7486
else
75-
nomulus_version=${version}
76-
schema_version="local"
87+
nomulus_env=${env}
88+
schema_env="local"
7789
fi
7890

79-
echo "Running test with -Pnomulus_version=${nomulus_version}" \
80-
"-Pschema_version=${schema_version}"
91+
echo "Running test with -Pnomulus_env=${nomulus_env}" \
92+
"-Pschema_env=${schema_env}" \
93+
"-PschemaTestArtifactsDir=${SCHEMA_TEST_ARTIFACTS_DIR}" \
8194

8295
# The https scheme in the Maven repo URL below is required for Kokoro. See
8396
# ./run_schema_check.sh for more information.
8497
(cd ${SCRIPT_DIR}/..; \
8598
./gradlew :integration:sqlIntegrationTest \
8699
-PdevProject=${dev_project} \
87-
-Pnomulus_version=${nomulus_version} \
88-
-Pschema_version=${schema_version} \
89-
-Ppublish_repo=https://storage.googleapis.com/${dev_project}-deployed-tags/maven)
100+
-Pnomulus_env=${nomulus_env} \
101+
-Pschema_env=${schema_env} \
102+
-PschemaTestArtifactsDir=${SCHEMA_TEST_ARTIFACTS_DIR})
90103
}
91104

92105
set -e
@@ -128,19 +141,16 @@ if [[ -z "${ENV}" ]]; then
128141
SANDBOX_VERSION=$(fetchVersion ${DEPLOYED_SYSTEM} sandbox ${DEV_PROJECT})
129142
PROD_VERSION=$(fetchVersion ${DEPLOYED_SYSTEM} production ${DEV_PROJECT})
130143
if [[ ${SANDBOX_VERSION} = ${PROD_VERSION} ]]; then
131-
VERSIONS=(${PROD_VERSION})
132144
echo "- sandbox and production at ${PROD_VERSION}"
145+
runTest ${DEPLOYED_SYSTEM} ${SANDBOX_VERSION} ${DEV_PROJECT} sandbox
133146
else
134-
VERSIONS=(${PROD_VERSION} ${SANDBOX_VERSION})
135147
echo "- sandbox at ${SANDBOX_VERSION}"
148+
runTest ${DEPLOYED_SYSTEM} ${SANDBOX_VERSION} ${DEV_PROJECT} sandbox
136149
echo "- production at ${PROD_VERSION}"
150+
runTest ${DEPLOYED_SYSTEM} ${PROD_VERSION} ${DEV_PROJECT} production
137151
fi
138152
else
139153
TARGET_VERSION=$(fetchVersion ${DEPLOYED_SYSTEM} ${ENV} ${DEV_PROJECT})
140-
VERSIONS=(${TARGET_VERSION})
141-
echo "- ${ENV} at ${TARGET_VERSION}"
154+
echo "- ${ENV} at ${TARGET_VERSION}"
155+
runTest ${DEPLOYED_SYSTEM} ${TARGET_VERSION} ${DEV_PROJECT} ${ENV}
142156
fi
143-
144-
for v in "${VERSIONS[@]}"; do
145-
runTest ${DEPLOYED_SYSTEM} ${v} ${DEV_PROJECT}
146-
done

integration/run_schema_check.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ fi
6767
sandbox_tag=$(fetchVersion sql sandbox ${DEV_PROJECT})
6868
echo "Checking Flyway scripts against schema in Sandbox (${sandbox_tag})."
6969

70-
# The URL of the Maven repo on GCS for the publish_repo parameter must use the
71-
# https scheme (https://storage.googleapis.com/{BUCKET}/{PATH}) in order to work
72-
# with Kokoro. Gradle's alternative gcs scheme does not work on Kokoro: a GCP
73-
# credential with proper scopes for GCS access is required even for public
74-
# buckets, however, Kokoro VM instances are not set up with such credentials.
75-
# Incidentally, gcs can be used on Cloud Build.
70+
if [[ -n "${SCHEMA_TEST_ARTIFACTS_DIR}" ]]; then
71+
echo "Using schema test jars downloaded to ${SCHEMA_TEST_ARTIFACTS_DIR}"
72+
else
73+
SCHEMA_TEST_ARTIFACTS_DIR=$(mktemp -d)
74+
echo "Created working dir ${SCHEMA_TEST_ARTIFACTS_DIR} for downloaded test jars."
75+
trap 'rm -rf ${SCHEMA_TEST_ARTIFACTS_DIR}' EXIT
76+
gcloud storage cp --verbosity=none \
77+
"gs://${DEV_PROJECT}-deployed-tags/schema-test-artifacts/*.jar" \
78+
"${SCHEMA_TEST_ARTIFACTS_DIR}"
79+
fi
80+
7681
(cd ${SCRIPT_DIR}/..; \
7782
./gradlew :db:schemaIncrementalDeployTest \
78-
-PbaseSchemaTag=${sandbox_tag} \
79-
-Ppublish_repo=https://storage.googleapis.com/${DEV_PROJECT}-deployed-tags/maven)
83+
-PschemaTestArtifactsDir="${SCHEMA_TEST_ARTIFACTS_DIR}")

0 commit comments

Comments
 (0)