Skip to content

Commit d41d325

Browse files
authored
buildscripts: simplify PSM interop Kokoro buildscripts (#11121) (#11164)
Integrates the new features of the the Kokoro PSM Interop install library introduced in grpc/psm-interop#73. Nearly all common functionality was moved from per-language/per-branch PSM Interop build scripts to [psm_interop_kokoro_lib.sh](https://github.com/grpc/psm-interop/blob/main/.kokoro/psm_interop_kokoro_lib.sh): 1. The list of tests in the each test suite 2. Per-test-suite flag customization 3. `run_test` methods 4. `build_docker_images_if_needed` methods 5. Generic `build_test_app_docker_images` methods (simple docker build + docker push + docker tag). grpc-java is one exception, as it doesn't run docker directly, but a cloudbuild flow. Now all PSM Interop jobs share the same buildscripts by all test suites: 1. buildscript that invokes the test: `psm-interop-test-{language}.sh` (configured as `build_file` in the build cfg) 2. buildscript that builds the xDS test client/server and publishes them as a Docker image: `psm-interop-build-{language}.sh` (conventional name called from `psm_interop_kokoro_lib.sh`) `psm-interop-test-{language}.sh`: 1. Sets `GRPC_LANGUAGE`, `BUILD_SCRIPT_DIR` environment variables. 2. Downloads the shared `psm_interop_kokoro_lib.sh` from the main branch of the psm-interop repo. 3. Sources `psm-interop-build-{language}.sh` 4. Calls `psm::run "${PSM_TEST_SUITE}"` (`PSM_TEST_SUITE` configured in the cfg file). `psm-interop-build-{language}.sh`: 1. Defines `psm::lang::build_docker_images` which is called from `psm_interop_kokoro_lib.sh`. 2. Invokes any repo-specific logic. 3. May use `psm::build::docker_images_generic` for generic Docker build, tag, push, or provide implement its own build/publish method. References: - b/288578634 - See the full list of the new features at grpc/psm-interop#73. - Additional fixes to the shared lib: grpc/psm-interop#78, grpc/psm-interop#79
1 parent b7bd89d commit d41d325

File tree

8 files changed

+132
-555
lines changed

8 files changed

+132
-555
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2024 gRPC authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
set -eo pipefail
16+
17+
# This file defines psm::lang::build_docker_images, which is directly called
18+
# from psm_interop_kokoro_lib.sh.
19+
20+
# Used locally.
21+
readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing"
22+
23+
#######################################
24+
# Builds the test app using gradle and smoke-checks its binaries
25+
# Globals:
26+
# SRC_DIR Absolute path to the source repo.
27+
# BUILD_APP_PATH
28+
# Arguments:
29+
# None
30+
# Outputs:
31+
# Writes the output of xds-test-client and xds-test-server --help to stderr
32+
#######################################
33+
_build_java_test_app() {
34+
psm::tools::log "Building Java test app"
35+
cd "${SRC_DIR}"
36+
37+
set -x
38+
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'" \
39+
./gradlew --no-daemon grpc-interop-testing:installDist -x test \
40+
-PskipCodegen=true -PskipAndroid=true --console=plain
41+
set +x
42+
43+
psm::tools::log "Test-run grpc-java PSM interop binaries"
44+
psm::tools::run_ignore_exit_code "${SRC_DIR}/${BUILD_APP_PATH}/bin/xds-test-client" --help
45+
psm::tools::run_ignore_exit_code "${SRC_DIR}/${BUILD_APP_PATH}/bin/xds-test-server" --help
46+
}
47+
48+
#######################################
49+
# Builds test app Docker images and pushes them to GCR
50+
# Globals:
51+
# BUILD_APP_PATH
52+
# SERVER_IMAGE_NAME: Test server Docker image name
53+
# CLIENT_IMAGE_NAME: Test client Docker image name
54+
# GIT_COMMIT: SHA-1 of git commit being built
55+
# TESTING_VERSION: version branch under test, f.e. v1.42.x, master
56+
# Arguments:
57+
# None
58+
# Outputs:
59+
# Writes the output of `gcloud builds submit` to stdout, stderr
60+
#######################################
61+
psm::lang::build_docker_images() {
62+
local java_build_log="${BUILD_LOGS_ROOT}/build-lang-java.log"
63+
_build_java_test_app |& tee "${java_build_log}"
64+
65+
psm::tools::log "Building Java xDS interop test app Docker images"
66+
local docker_dir="${SRC_DIR}/buildscripts/xds-k8s"
67+
local build_dir
68+
build_dir="$(mktemp -d)"
69+
70+
# Copy Docker files, log properties, and the test app to the build dir
71+
{
72+
cp -v "${docker_dir}/"*.Dockerfile "${build_dir}"
73+
cp -v "${docker_dir}/"*.properties "${build_dir}"
74+
cp -rv "${SRC_DIR}/${BUILD_APP_PATH}" "${build_dir}"
75+
} >> "${java_build_log}"
76+
77+
78+
# cloudbuild.yaml substitution variables
79+
local substitutions=""
80+
substitutions+="_SERVER_IMAGE_NAME=${SERVER_IMAGE_NAME},"
81+
substitutions+="_CLIENT_IMAGE_NAME=${CLIENT_IMAGE_NAME},"
82+
substitutions+="COMMIT_SHA=${GIT_COMMIT},"
83+
substitutions+="BRANCH_NAME=${TESTING_VERSION},"
84+
85+
# Run Google Cloud Build
86+
gcloud builds submit "${build_dir}" \
87+
--config="${docker_dir}/cloudbuild.yaml" \
88+
--substitutions="${substitutions}" \
89+
| tee -a "${java_build_log}"
90+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
# Input parameters to psm:: methods of the install script.
5+
readonly GRPC_LANGUAGE="java"
6+
readonly BUILD_SCRIPT_DIR="$(dirname "$0")"
7+
8+
# Used locally.
9+
readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/psm-interop/${TEST_DRIVER_BRANCH:-main}/.kokoro/psm_interop_kokoro_lib.sh"
10+
11+
psm::lang::source_install_lib() {
12+
echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}"
13+
local install_lib
14+
# Download to a tmp file.
15+
install_lib="$(mktemp -d)/psm_interop_kokoro_lib.sh"
16+
curl -s --retry-connrefused --retry 5 -o "${install_lib}" "${TEST_DRIVER_INSTALL_SCRIPT_URL}"
17+
# Checksum.
18+
if command -v sha256sum &> /dev/null; then
19+
echo "Install script checksum:"
20+
sha256sum "${install_lib}"
21+
fi
22+
source "${install_lib}"
23+
}
24+
25+
psm::lang::source_install_lib
26+
source "${BUILD_SCRIPT_DIR}/psm-interop-build-${GRPC_LANGUAGE}.sh"
27+
psm::run "${PSM_TEST_SUITE}"

buildscripts/kokoro/psm-security.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Config file for internal CI
22

33
# Location of the continuous shell script in repository.
4-
build_file: "grpc-java/buildscripts/kokoro/psm-security.sh"
4+
build_file: "grpc-java/buildscripts/kokoro/psm-interop-test-java.sh"
55
timeout_mins: 240
66

77
action {
@@ -11,3 +11,7 @@ action {
1111
strip_prefix: "artifacts"
1212
}
1313
}
14+
env_vars {
15+
key: "PSM_TEST_SUITE"
16+
value: "security"
17+
}

buildscripts/kokoro/psm-security.sh

Lines changed: 0 additions & 185 deletions
This file was deleted.

buildscripts/kokoro/xds_k8s_lb.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Config file for internal CI
22

33
# Location of the continuous shell script in repository.
4-
build_file: "grpc-java/buildscripts/kokoro/xds_k8s_lb.sh"
4+
build_file: "grpc-java/buildscripts/kokoro/psm-interop-test-java.sh"
55
timeout_mins: 180
66

77
action {
@@ -11,3 +11,7 @@ action {
1111
strip_prefix: "artifacts"
1212
}
1313
}
14+
env_vars {
15+
key: "PSM_TEST_SUITE"
16+
value: "lb"
17+
}

0 commit comments

Comments
 (0)