forked from bazelbuild/rules_k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-e2e.sh
executable file
·129 lines (107 loc) · 3.8 KB
/
test-e2e.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# 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 -o errexit
set -o nounset
set -o xtrace
# Helper command for local debugging.
# Note: prow jobs already run inside a container
run-in-container() {
cd "$(dirname "${BASH_SOURCE}")"
echo "startup --host_jvm_args=-Duser.name=$USER" > /tmp/test-e2e.bazelrc
args=(
# Ensure we do not deploy to namespace root
# But don't use -u $(id -u) as this is a pain
-e "USER=$USER"
-v /tmp/test-e2e.bazelrc:/root/.bazelrc
# Map rules_k8s repo into /workspace
-v "$PWD":/workspace
-w /workspace
# Map in credentials
-v "$HOME/.kube":/root/.kube
-v "$HOME/.config/gcloud":/root/.config/gcloud
# Remove image after completion
--rm=true gcr.io/rules-k8s/gcloud-bazel:latest-"$USER"
# Run this script
"./$(basename "${BASH_SOURCE}")"
)
docker run "${args[@]}" "$@"
exit 0
}
if [[ "${1:-}" == "--container" ]]; then
shift
run-in-container "$@"
fi
check-plat() {
local plat="$(uname -s)"
if [[ $plat != Linux ]]; then
echo "Consider using --container" >&2
echo "System must be Linux, found: $plat" >&2
return 1
fi
}
check-plat
set +o xtrace
if [[ -n "${GOOGLE_JSON_KEY:-}" ]]; then
# Log into gcloud
echo -n "${GOOGLE_JSON_KEY}" > keyfile.json
gcloud auth activate-service-account --key-file keyfile.json
rm -f keyfile.json
fi
set -o xtrace
# Setup our credentials
gcloud container clusters get-credentials testing --project=rules-k8s --zone=us-central1-f
gcloud auth configure-docker --quiet
# Check our installs.
bazel version
gcloud version
kubectl version
# Don't build/test the prow image as it requires Docker
EXCLUDED_TARGETS="-//images/gcloud-bazel:gcloud_install -//images/gcloud-bazel:gcloud_push"
# copt flag is needed to compila a gRPC dependency (@udp)
# verbose_failures is added for better error debugging
BAZEL_FLAGS="--copt=-Wno-c99-extensions --verbose_failures"
# Install buildifier 0.22.0 and run lint checks
wget -q https://github.com/bazelbuild/buildtools/releases/download/0.22.0/buildifier
chmod +x ./buildifier
# Check that all of our tools and samples build
bazel build $BAZEL_FLAGS -- //... $EXCLUDED_TARGETS
bazel test $BAZEL_FLAGS -- //... $EXCLUDED_TARGETS
# Run the garbage collection script to delete old namespaces.
bazel run $BAZEL_FLAGS -- //examples:e2e_gc
# Create a unique namespace for this job using the repo name and the build id
E2E_NAMESPACE="build-${BUILD_ID:-0}"
kubectl get "namespaces/${E2E_NAMESPACE}" &> /dev/null || kubectl create namespace "${E2E_NAMESPACE}"
delete() {
# Delete the namespace
echo "Deleting kubernetes namespace ${E2E_NAMESPACE}"
# Delete the namespace
kubectl delete namespaces/$E2E_NAMESPACE
}
# Setup a trap to delete the namespace on error
set +o xtrace
trap "echo FAILED, cleaning up...; delete" EXIT
set -o xtrace
# Run end-to-end integration testing.
# First, GRPC.
./examples/hellogrpc/e2e-test.sh remote $E2E_NAMESPACE cc java go py
# Second, HTTP.
./examples/hellohttp/e2e-test.sh remote $E2E_NAMESPACE py java go nodejs
# Third, TODO Controller.
# chrislovecnm - disabled till this is less flakey
# ./examples/todocontroller/e2e-test.sh remote $E2E_NAMESPACE py
# Delete everything as we are now done
delete
# Replace the exit trap with a pass message
trap "echo PASS" EXIT