...

Text file src/cloud.google.com/go/internal/kokoro/environment.sh

Documentation: cloud.google.com/go/internal/kokoro

     1#!/bin/bash
     2# Copyright 2021 Google LLC
     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# A suite of tests offered by https://github.com/googleapis/env-tests-logging
    17# That allows deploying and testing features in live GCP services.
    18# Currently only configured to test logging & error reporting
    19
    20set -eo pipefail
    21
    22# Test prechecks
    23if [[ -z "${ENVIRONMENT:-}" ]]; then
    24  echo "ENVIRONMENT not set. Exiting"
    25  exit 1
    26fi
    27
    28if [[ -z "${PROJECT_ROOT:-}"  ]]; then
    29    PROJECT_ROOT="github/google-cloud-go"
    30fi
    31
    32# add kokoro labels for testgrid filtering
    33export PRODUCT_AREA_LABEL=observability
    34export PRODUCT_LABEL=logging
    35export LANGUAGE_LABEL=go
    36
    37# Add the test module as a submodule to the repo.
    38cd "${KOKORO_ARTIFACTS_DIR}/github/google-cloud-go/internal/"
    39git submodule add https://github.com/googleapis/env-tests-logging
    40cd "env-tests-logging/"
    41export ENV_TEST_PY_VERSION=3.9
    42echo "using python version: $ENV_TEST_PY_VERSION"
    43
    44# run tests from git tag golang-envtest-pin when available
    45TAG_ID="golang-envtest-pin"
    46git fetch --tags
    47if [ $(git tag -l "$TAG_ID")  ]; then
    48  git -c advice.detachedHead=false checkout $TAG_ID
    49else
    50  echo "WARNING: tag $TAG_ID not found in repo"
    51fi
    52echo "running env-tests-logging at commit: $(git rev-parse HEAD)"
    53
    54# Disable buffering, so that the logs stream through.
    55export PYTHONUNBUFFERED=1
    56
    57# Debug: show build environment
    58env | grep KOKORO
    59
    60# Set up service account credentials
    61export GOOGLE_APPLICATION_CREDENTIALS=$KOKORO_KEYSTORE_DIR/72523_go_integration_service_account
    62gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
    63
    64set -x
    65export PROJECT_ID="dulcet-port-762"
    66gcloud config set project $PROJECT_ID
    67gcloud config set compute/zone us-central1-b
    68
    69# Authenticate docker
    70gcloud auth configure-docker -q
    71
    72# create a unique id for this run
    73UUID=$(python3  -c 'import uuid; print(uuid.uuid1())' | head -c 7)
    74export ENVCTL_ID=ci-$UUID
    75echo $ENVCTL_ID
    76
    77# If App Engine, install app-engine-go component
    78if [[ $ENVIRONMENT == *"appengine"* ]]; then
    79  apt-get install google-cloud-sdk-app-engine-go -y | cat
    80fi
    81
    82# If Kubernetes, install kubectl component
    83if [[ $ENVIRONMENT == *"kubernetes"* ]]; then
    84  curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
    85  chmod +x kubectl
    86  mkdir -p ~/.local/bin
    87  mv ./kubectl ~/.local/bin
    88  export PATH=$PATH:~/.local/bin/
    89  # install auth plugin
    90  apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
    91  export USE_GKE_GCLOUD_AUTH_PLUGIN=True
    92fi
    93
    94# If Functions, use python3.8, since that's what's in go116 container
    95if [[ $ENVIRONMENT == *"functions"* ]]; then
    96  export ENV_TEST_PY_VERSION=3.8
    97  python3 -m pip install nox
    98fi
    99
   100# Run the environment test for the specified GCP service
   101set +e
   102python3 -m nox --session "tests(language='go', platform='$ENVIRONMENT')"
   103TEST_STATUS_CODE=$?
   104
   105# destroy resources
   106echo "cleaning up..."
   107./envctl/envctl go $ENVIRONMENT destroy
   108
   109# exit with proper status code
   110exit $TEST_STATUS_CODE

View as plain text