Skip to content

Commit

Permalink
buildscripts: simplify PSM interop Kokoro buildscripts (grpc#11121)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sergiitk committed May 6, 2024
1 parent c16726a commit 5e3c7d8
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 552 deletions.
90 changes: 90 additions & 0 deletions buildscripts/kokoro/psm-interop-build-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
# Copyright 2024 gRPC authors.
#
# 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.
set -eo pipefail

# This file defines psm::lang::build_docker_images, which is directly called
# from psm_interop_kokoro_lib.sh.

# Used locally.
readonly BUILD_APP_PATH="interop-testing/build/install/grpc-interop-testing"

#######################################
# Builds the test app using gradle and smoke-checks its binaries
# Globals:
# SRC_DIR Absolute path to the source repo.
# BUILD_APP_PATH
# Arguments:
# None
# Outputs:
# Writes the output of xds-test-client and xds-test-server --help to stderr
#######################################
_build_java_test_app() {
psm::tools::log "Building Java test app"
cd "${SRC_DIR}"

set -x
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'" \
./gradlew --no-daemon grpc-interop-testing:installDist -x test \
-PskipCodegen=true -PskipAndroid=true --console=plain
set +x

psm::tools::log "Test-run grpc-java PSM interop binaries"
psm::tools::run_ignore_exit_code "${SRC_DIR}/${BUILD_APP_PATH}/bin/xds-test-client" --help
psm::tools::run_ignore_exit_code "${SRC_DIR}/${BUILD_APP_PATH}/bin/xds-test-server" --help
}

#######################################
# Builds test app Docker images and pushes them to GCR
# Globals:
# BUILD_APP_PATH
# SERVER_IMAGE_NAME: Test server Docker image name
# CLIENT_IMAGE_NAME: Test client Docker image name
# GIT_COMMIT: SHA-1 of git commit being built
# TESTING_VERSION: version branch under test, f.e. v1.42.x, master
# Arguments:
# None
# Outputs:
# Writes the output of `gcloud builds submit` to stdout, stderr
#######################################
psm::lang::build_docker_images() {
local java_build_log="${BUILD_LOGS_ROOT}/build-lang-java.log"
_build_java_test_app |& tee "${java_build_log}"

psm::tools::log "Building Java xDS interop test app Docker images"
local docker_dir="${SRC_DIR}/buildscripts/xds-k8s"
local build_dir
build_dir="$(mktemp -d)"

# Copy Docker files, log properties, and the test app to the build dir
{
cp -v "${docker_dir}/"*.Dockerfile "${build_dir}"
cp -v "${docker_dir}/"*.properties "${build_dir}"
cp -rv "${SRC_DIR}/${BUILD_APP_PATH}" "${build_dir}"
} >> "${java_build_log}"


# cloudbuild.yaml substitution variables
local substitutions=""
substitutions+="_SERVER_IMAGE_NAME=${SERVER_IMAGE_NAME},"
substitutions+="_CLIENT_IMAGE_NAME=${CLIENT_IMAGE_NAME},"
substitutions+="COMMIT_SHA=${GIT_COMMIT},"
substitutions+="BRANCH_NAME=${TESTING_VERSION},"

# Run Google Cloud Build
gcloud builds submit "${build_dir}" \
--config="${docker_dir}/cloudbuild.yaml" \
--substitutions="${substitutions}" \
| tee -a "${java_build_log}"
}
27 changes: 27 additions & 0 deletions buildscripts/kokoro/psm-interop-test-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -eo pipefail

# Input parameters to psm:: methods of the install script.
readonly GRPC_LANGUAGE="java"
readonly BUILD_SCRIPT_DIR="$(dirname "$0")"

# Used locally.
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"

psm::lang::source_install_lib() {
echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}"
local install_lib
# Download to a tmp file.
install_lib="$(mktemp -d)/psm_interop_kokoro_lib.sh"
curl -s --retry-connrefused --retry 5 -o "${install_lib}" "${TEST_DRIVER_INSTALL_SCRIPT_URL}"
# Checksum.
if command -v sha256sum &> /dev/null; then
echo "Install script checksum:"
sha256sum "${install_lib}"
fi
source "${install_lib}"
}

psm::lang::source_install_lib
source "${BUILD_SCRIPT_DIR}/psm-interop-build-${GRPC_LANGUAGE}.sh"
psm::run "${PSM_TEST_SUITE}"
6 changes: 5 additions & 1 deletion buildscripts/kokoro/psm-security.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Config file for internal CI

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

action {
Expand All @@ -11,3 +11,7 @@ action {
strip_prefix: "artifacts"
}
}
env_vars {
key: "PSM_TEST_SUITE"
value: "security"
}
185 changes: 0 additions & 185 deletions buildscripts/kokoro/psm-security.sh

This file was deleted.

6 changes: 5 additions & 1 deletion buildscripts/kokoro/xds_k8s_lb.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Config file for internal CI

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

action {
Expand All @@ -11,3 +11,7 @@ action {
strip_prefix: "artifacts"
}
}
env_vars {
key: "PSM_TEST_SUITE"
value: "lb"
}
Loading

0 comments on commit 5e3c7d8

Please sign in to comment.