-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathenvironment_tests.sh
executable file
·86 lines (69 loc) · 2.49 KB
/
environment_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Copyright 2021 Google LLC
#
# 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
#
# https://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 -eox pipefail
if [[ -z "${ENVIRONMENT:-}" ]]; then
echo "ENVIRONMENT not set. Exiting"
exit 1
fi
if [[ -z "${PROJECT_ROOT:-}" ]]; then
PROJECT_ROOT="${KOKORO_ARTIFACTS_DIR}/github/java-logging"
fi
# make sure submodule is up to date
cd "$PROJECT_ROOT"
git config --global --add safe.directory '*'
git config --global --add safe.directory /tmpfs/src/github/java-logging
git submodule update --init --recursive
cd "${PROJECT_ROOT}/env-tests-logging"
# Disable buffering, so that the logs stream through.
export PYTHONUNBUFFERED=1
# Setup service account credentials.
export GOOGLE_APPLICATION_CREDENTIALS=$KOKORO_GFILE_DIR/secret_manager/java-it-service-account
gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
gcloud config get-value project
# Setup project id.
gcloud config set project $GOOGLE_CLOUD_PROJECT
# set a default zone.
gcloud config set compute/zone us-central1-b
# authenticate docker
gcloud auth configure-docker -q
# Remove old nox
python3 -m pip uninstall --yes --quiet nox-automation
# Install nox
python3 -m pip install --upgrade --quiet nox
python3 -m nox --version
# Install kubectl
if [[ "${ENVIRONMENT}" == "kubernetes" ]]; then
curl -LO https://dl.k8s.io/release/v1.20.0/bin/linux/amd64/kubectl
chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin
export PATH=$PATH:~/.local/bin
# install auth plugin
gcloud components install gke-gcloud-auth-plugin -q
export USE_GKE_GCLOUD_AUTH_PLUGIN=True
fi
# create a unique id for this run
UUID=$(python -c 'import uuid; print(uuid.uuid1())' | head -c 7)
export ENVCTL_ID=ci-$UUID
echo $ENVCTL_ID
# Run the specified environment test
set +e
python3 -m nox --session "tests(language='java', platform='$ENVIRONMENT')"
TEST_STATUS_CODE=$?
# destroy resources
echo "cleaning up..."
${PROJECT_ROOT}/env-tests-logging/envctl/envctl java $ENVIRONMENT destroy
# exit with proper status code
exit $TEST_STATUS_CODE