gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/grpc/test/kokoro/xds_url_map.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2021 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 16 set -eo pipefail 17 18 # Constants 19 readonly GITHUB_REPOSITORY_NAME="grpc-go" 20 readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/grpc/${TEST_DRIVER_BRANCH:-master}/tools/internal_ci/linux/grpc_xds_k8s_install_test_driver.sh" 21 ## xDS test client Docker images 22 readonly CLIENT_IMAGE_NAME="gcr.io/grpc-testing/xds-interop/go-client" 23 readonly FORCE_IMAGE_BUILD="${FORCE_IMAGE_BUILD:-0}" 24 25 ####################################### 26 # Builds test app Docker images and pushes them to GCR 27 # Globals: 28 # CLIENT_IMAGE_NAME: Test client Docker image name 29 # GIT_COMMIT: SHA-1 of git commit being built 30 # Arguments: 31 # None 32 # Outputs: 33 # Writes the output of `gcloud builds submit` to stdout, stderr 34 ####################################### 35 build_test_app_docker_images() { 36 echo "Building Go xDS interop test app Docker images" 37 docker build -f "${SRC_DIR}/interop/xds/client/Dockerfile" -t "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" "${SRC_DIR}" 38 gcloud -q auth configure-docker 39 docker push "${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" 40 } 41 42 ####################################### 43 # Builds test app and its docker images unless they already exist 44 # Globals: 45 # CLIENT_IMAGE_NAME: Test client Docker image name 46 # GIT_COMMIT: SHA-1 of git commit being built 47 # FORCE_IMAGE_BUILD 48 # Arguments: 49 # None 50 # Outputs: 51 # Writes the output to stdout, stderr 52 ####################################### 53 build_docker_images_if_needed() { 54 # Check if images already exist 55 client_tags="$(gcloud_gcr_list_image_tags "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}")" 56 printf "Client image: %s:%s\n" "${CLIENT_IMAGE_NAME}" "${GIT_COMMIT}" 57 echo "${client_tags:-Client image not found}" 58 59 # Build if any of the images are missing, or FORCE_IMAGE_BUILD=1 60 if [[ "${FORCE_IMAGE_BUILD}" == "1" || -z "${client_tags}" ]]; then 61 build_test_app_docker_images 62 else 63 echo "Skipping Go test app build" 64 fi 65 } 66 67 ####################################### 68 # Executes the test case 69 # Globals: 70 # TEST_DRIVER_FLAGFILE: Relative path to test driver flagfile 71 # KUBE_CONTEXT: The name of kubectl context with GKE cluster access 72 # TEST_XML_OUTPUT_DIR: Output directory for the test xUnit XML report 73 # CLIENT_IMAGE_NAME: Test client Docker image name 74 # GIT_COMMIT: SHA-1 of git commit being built 75 # Arguments: 76 # Test case name 77 # Outputs: 78 # Writes the output of test execution to stdout, stderr 79 # Test xUnit report to ${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml 80 ####################################### 81 run_test() { 82 # Test driver usage: 83 # https://github.com/grpc/grpc/tree/master/tools/run_tests/xds_k8s_test_driver#basic-usage 84 local test_name="${1:?Usage: run_test test_name}" 85 set -x 86 python -m "tests.${test_name}" \ 87 --flagfile="${TEST_DRIVER_FLAGFILE}" \ 88 --kube_context="${KUBE_CONTEXT}" \ 89 --client_image="${CLIENT_IMAGE_NAME}:${GIT_COMMIT}" \ 90 --testing_version=$(echo "$KOKORO_JOB_NAME" | sed -E 's|^grpc/go/([^/]+)/.*|\1|') \ 91 --xml_output_file="${TEST_XML_OUTPUT_DIR}/${test_name}/sponge_log.xml" \ 92 --flagfile="config/url-map.cfg" 93 set +x 94 } 95 96 ####################################### 97 # Main function: provision software necessary to execute tests, and run them 98 # Globals: 99 # KOKORO_ARTIFACTS_DIR 100 # GITHUB_REPOSITORY_NAME 101 # SRC_DIR: Populated with absolute path to the source repo 102 # TEST_DRIVER_REPO_DIR: Populated with the path to the repo containing 103 # the test driver 104 # TEST_DRIVER_FULL_DIR: Populated with the path to the test driver source code 105 # TEST_DRIVER_FLAGFILE: Populated with relative path to test driver flagfile 106 # TEST_XML_OUTPUT_DIR: Populated with the path to test xUnit XML report 107 # GIT_ORIGIN_URL: Populated with the origin URL of git repo used for the build 108 # GIT_COMMIT: Populated with the SHA-1 of git commit being built 109 # GIT_COMMIT_SHORT: Populated with the short SHA-1 of git commit being built 110 # KUBE_CONTEXT: Populated with name of kubectl context with GKE cluster access 111 # Arguments: 112 # None 113 # Outputs: 114 # Writes the output of test execution to stdout, stderr 115 ####################################### 116 main() { 117 local script_dir 118 script_dir="$(dirname "$0")" 119 120 # Source the test driver from the master branch. 121 echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" 122 source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" 123 124 activate_gke_cluster GKE_CLUSTER_PSM_BASIC 125 126 set -x 127 if [[ -n "${KOKORO_ARTIFACTS_DIR}" ]]; then 128 kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" 129 else 130 local_setup_test_driver "${script_dir}" 131 fi 132 build_docker_images_if_needed 133 # Run tests 134 cd "${TEST_DRIVER_FULL_DIR}" 135 run_test url_map 136 } 137 138 main "$@"