|
| 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 | +} |
0 commit comments