forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_ci.sh
executable file
·300 lines (280 loc) · 11.8 KB
/
do_ci.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
# Run a CI build/test target, e.g. docs, asan.
set -e
build_setup_args=""
if [[ "$1" == "fix_format" || "$1" == "check_format" || "$1" == "check_repositories" || \
"$1" == "check_spelling" || "$1" == "fix_spelling" || "$1" == "bazel.clang_tidy" || \
"$1" == "check_spelling_pedantic" || "$1" == "fix_spelling_pedantic" || "$1" == "bazel.compile_time_options" ]]; then
build_setup_args="-nofetch"
fi
. "$(dirname "$0")"/setup_gcs_cache.sh
. "$(dirname "$0")"/build_setup.sh $build_setup_args
cd "${ENVOY_SRCDIR}"
echo "building using ${NUM_CPUS} CPUs"
function collect_build_profile() {
cp -f "$(bazel info output_base)/command.profile" "${ENVOY_BUILD_PROFILE}/$1.profile" || true
}
function bazel_with_collection() {
declare -r BAZEL_OUTPUT="${ENVOY_SRCDIR}"/bazel.output.txt
bazel $* | tee "${BAZEL_OUTPUT}"
declare BAZEL_STATUS="${PIPESTATUS[0]}"
if [ "${BAZEL_STATUS}" != "0" ]
then
declare -r FAILED_TEST_LOGS="$(grep " /build.*test.log" "${BAZEL_OUTPUT}" | sed -e 's/ \/build.*\/testlogs\/\(.*\)/\1/')"
pushd bazel-testlogs
for f in ${FAILED_TEST_LOGS}
do
cp --parents -f $f "${ENVOY_FAILED_TEST_LOGS}"
done
popd
exit "${BAZEL_STATUS}"
fi
collect_build_profile $1
}
function bazel_release_binary_build() {
echo "Building..."
bazel build ${BAZEL_BUILD_OPTIONS} -c opt //source/exe:envoy-static
collect_build_profile release_build
# Copy the envoy-static binary somewhere that we can access outside of the
# container.
cp -f \
"${ENVOY_SRCDIR}"/bazel-bin/source/exe/envoy-static \
"${ENVOY_DELIVERY_DIR}"/envoy
# TODO(mattklein123): Replace this with caching and a different job which creates images.
echo "Copying release binary for image build..."
mkdir -p "${ENVOY_SRCDIR}"/build_release
cp -f "${ENVOY_DELIVERY_DIR}"/envoy "${ENVOY_SRCDIR}"/build_release
mkdir -p "${ENVOY_SRCDIR}"/build_release_stripped
strip "${ENVOY_DELIVERY_DIR}"/envoy -o "${ENVOY_SRCDIR}"/build_release_stripped/envoy
}
function bazel_debug_binary_build() {
echo "Building..."
bazel build ${BAZEL_BUILD_OPTIONS} -c dbg //source/exe:envoy-static
collect_build_profile debug_build
# Copy the envoy-static binary somewhere that we can access outside of the
# container.
cp -f \
"${ENVOY_SRCDIR}"/bazel-bin/source/exe/envoy-static \
"${ENVOY_DELIVERY_DIR}"/envoy-debug
}
if [[ "$1" == "bazel.release" ]]; then
setup_gcc_toolchain
echo "bazel release build with tests..."
bazel_release_binary_build
if [[ $# -gt 1 ]]; then
shift
echo "Testing $* ..."
# Run only specified tests. Argument can be a single test
# (e.g. '//test/common/common:assert_test') or a test group (e.g. '//test/common/...')
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c opt $*
else
echo "Testing..."
# We have various test binaries in the test directory such as tools, benchmarks, etc. We
# run a build pass to make sure they compile.
# Reduce the amount of memory and number of cores Bazel tries to use to
# prevent it from launching too many subprocesses. This should prevent the
# system from running out of memory and killing tasks. See discussion on
# https://github.com/envoyproxy/envoy/pull/5611.
# TODO(akonradi): use --local_cpu_resources flag once Bazel has a release
# after 0.21.
[ -z "$CIRCLECI" ] || export BAZEL_BUILD_OPTIONS="${BAZEL_BUILD_OPTIONS} --local_resources=12288,5,1"
[ -z "$CIRCLECI" ] || export BAZEL_TEST_OPTIONS="${BAZEL_TEST_OPTIONS} --local_resources=12288,5,1 --local_test_jobs=8"
bazel build ${BAZEL_BUILD_OPTIONS} -c opt //include/... //source/... //test/...
# Now run all of the tests which should already be compiled.
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c opt //test/...
fi
exit 0
elif [[ "$1" == "bazel.release.server_only" ]]; then
setup_gcc_toolchain
echo "bazel release build..."
bazel_release_binary_build
exit 0
elif [[ "$1" == "bazel.debug" ]]; then
setup_gcc_toolchain
echo "bazel debug build with tests..."
bazel_debug_binary_build
echo "Testing..."
bazel test ${BAZEL_TEST_OPTIONS} -c dbg //test/...
exit 0
elif [[ "$1" == "bazel.debug.server_only" ]]; then
setup_gcc_toolchain
echo "bazel debug build..."
bazel_debug_binary_build
exit 0
elif [[ "$1" == "bazel.asan" ]]; then
setup_clang_toolchain
echo "bazel ASAN/UBSAN debug build with tests"
echo "Building and testing envoy tests..."
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c dbg --config=clang-asan //test/...
echo "Building and testing envoy-filter-example tests..."
pushd "${ENVOY_FILTER_EXAMPLE_SRCDIR}"
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c dbg --config=clang-asan \
//:echo2_integration_test //:envoy_binary_test
popd
# Also validate that integration test traffic tapping (useful when debugging etc.)
# works. This requires that we set TAP_PATH. We do this under bazel.asan to
# ensure a debug build in CI.
echo "Validating integration test traffic tapping..."
TAP_TMP=/tmp/tap/
rm -rf "${TAP_TMP}"
mkdir -p "${TAP_TMP}"
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c dbg --config=clang-asan \
//test/extensions/transport_sockets/tls/integration:ssl_integration_test \
--test_env=TAP_PATH="${TAP_TMP}/tap"
# Verify that some pb_text files have been created. We can't check for pcap,
# since tcpdump is not available in general due to CircleCI lack of support
# for privileged Docker executors.
ls -l "${TAP_TMP}"/tap_*.pb_text > /dev/null
exit 0
elif [[ "$1" == "bazel.tsan" ]]; then
setup_clang_toolchain
echo "bazel TSAN debug build with tests"
echo "Building and testing envoy tests..."
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c dbg --config=clang-tsan //test/...
echo "Building and testing envoy-filter-example tests..."
cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}"
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c dbg --config=clang-tsan \
//:echo2_integration_test //:envoy_binary_test
exit 0
elif [[ "$1" == "bazel.dev" ]]; then
setup_clang_toolchain
# This doesn't go into CI but is available for developer convenience.
echo "bazel fastbuild build with tests..."
echo "Building..."
bazel build ${BAZEL_BUILD_OPTIONS} -c fastbuild //source/exe:envoy-static
# Copy the envoy-static binary somewhere that we can access outside of the
# container for developers.
cp -f \
"${ENVOY_SRCDIR}"/bazel-bin/source/exe/envoy-static \
"${ENVOY_DELIVERY_DIR}"/envoy-fastbuild
echo "Building and testing..."
bazel test ${BAZEL_TEST_OPTIONS} -c fastbuild //test/...
exit 0
elif [[ "$1" == "bazel.compile_time_options" ]]; then
# Right now, none of the available compile-time options conflict with each other. If this
# changes, this build type may need to be broken up.
# TODO(mpwarres): remove quiche=enabled once QUICHE is built by default.
COMPILE_TIME_OPTIONS="\
--config libc++ \
--define signal_trace=disabled \
--define hot_restart=disabled \
--define google_grpc=disabled \
--define boringssl=fips \
--define log_debug_assert_in_release=enabled \
--define quiche=enabled \
"
setup_clang_toolchain
# This doesn't go into CI but is available for developer convenience.
echo "bazel with different compiletime options build with tests..."
# Building all the dependencies from scratch to link them against libc++.
echo "Building..."
bazel build ${BAZEL_BUILD_OPTIONS} ${COMPILE_TIME_OPTIONS} -c dbg //source/exe:envoy-static
echo "Building and testing..."
bazel test ${BAZEL_TEST_OPTIONS} ${COMPILE_TIME_OPTIONS} -c dbg //test/...
# "--define log_debug_assert_in_release=enabled" must be tested with a release build, so run only
# these tests under "-c opt" to save time in CI.
bazel test ${BAZEL_TEST_OPTIONS} ${COMPILE_TIME_OPTIONS} -c opt //test/common/common:assert_test //test/server:server_test
exit 0
elif [[ "$1" == "bazel.ipv6_tests" ]]; then
# This is around until Circle supports IPv6. We try to run a limited set of IPv6 tests as fast
# as possible for basic sanity testing.
# Hack to avoid returning IPv6 DNS
sed -i 's_#precedence ::ffff:0:0/96 100_precedence ::ffff:0:0/96 100_' /etc/gai.conf
# Debug IPv6 network issues
apt-get update && apt-get install -y dnsutils net-tools curl && \
ifconfig && \
route -A inet -A inet6 && \
curl -v https://go.googlesource.com && \
curl -6 -v https://go.googlesource.com && \
dig go.googlesource.com A go.googlesource.com AAAA
setup_clang_toolchain
echo "Testing..."
bazel_with_collection test ${BAZEL_TEST_OPTIONS} --test_env=ENVOY_IP_TEST_VERSIONS=v6only -c fastbuild \
//test/integration/... //test/common/network/...
exit 0
elif [[ "$1" == "bazel.api" ]]; then
setup_clang_toolchain
echo "Building API..."
bazel build ${BAZEL_BUILD_OPTIONS} -c fastbuild @envoy_api//envoy/...
echo "Testing API..."
bazel_with_collection test ${BAZEL_TEST_OPTIONS} -c fastbuild @envoy_api//test/... @envoy_api//tools/... \
@envoy_api//tools:tap2pcap_test
exit 0
elif [[ "$1" == "bazel.coverage" ]]; then
setup_gcc_toolchain
echo "bazel coverage build with tests..."
# gcovr is a pain to run with `bazel run`, so package it up into a
# relocatable and hermetic-ish .par file.
bazel build @com_github_gcovr_gcovr//:gcovr.par
export GCOVR="/tmp/gcovr.par"
cp -f "${ENVOY_SRCDIR}/bazel-bin/external/com_github_gcovr_gcovr/gcovr.par" ${GCOVR}
# Reduce the amount of memory and number of cores Bazel tries to use to
# prevent it from launching too many subprocesses. This should prevent the
# system from running out of memory and killing tasks. See discussion on
# https://github.com/envoyproxy/envoy/pull/5611.
# TODO(akonradi): use --local_cpu_resources flag once Bazel has a release
# after 0.21.
[ -z "$CIRCLECI" ] || export BAZEL_TEST_OPTIONS="${BAZEL_TEST_OPTIONS} --local_resources=12288,4,1"
test/run_envoy_bazel_coverage.sh
collect_build_profile coverage
exit 0
elif [[ "$1" == "bazel.clang_tidy" ]]; then
setup_clang_toolchain
ci/run_clang_tidy.sh
exit 0
elif [[ "$1" == "bazel.coverity" ]]; then
# Coverity Scan version 2017.07 fails to analyze the entirely of the Envoy
# build when compiled with Clang 5. Revisit when Coverity Scan explicitly
# supports Clang 5. Until this issue is resolved, run Coverity Scan with
# the GCC toolchain.
setup_gcc_toolchain
echo "bazel Coverity Scan build"
echo "Building..."
/build/cov-analysis/bin/cov-build --dir "${ENVOY_BUILD_DIR}"/cov-int bazel build --action_env=LD_PRELOAD ${BAZEL_BUILD_OPTIONS} \
-c opt //source/exe:envoy-static
# tar up the coverity results
tar czvf "${ENVOY_BUILD_DIR}"/envoy-coverity-output.tgz -C "${ENVOY_BUILD_DIR}" cov-int
# Copy the Coverity results somewhere that we can access outside of the container.
cp -f \
"${ENVOY_BUILD_DIR}"/envoy-coverity-output.tgz \
"${ENVOY_DELIVERY_DIR}"/envoy-coverity-output.tgz
exit 0
elif [[ "$1" == "fix_format" ]]; then
echo "fix_format..."
./tools/check_format.py fix
exit 0
elif [[ "$1" == "check_format" ]]; then
echo "check_format_test..."
./tools/check_format_test_helper.py --log=WARN
echo "check_format..."
./tools/check_format.py check
./tools/format_python_tools.sh check
exit 0
elif [[ "$1" == "check_repositories" ]]; then
echo "check_repositories..."
./tools/check_repositories.sh
exit 0
elif [[ "$1" == "check_spelling" ]]; then
echo "check_spelling..."
./tools/check_spelling.sh check
exit 0
elif [[ "$1" == "fix_spelling" ]];then
echo "fix_spell..."
./tools/check_spelling.sh fix
exit 0
elif [[ "$1" == "check_spelling_pedantic" ]]; then
echo "check_spelling_pedantic..."
./tools/check_spelling_pedantic.py check
exit 0
elif [[ "$1" == "fix_spelling_pedantic" ]]; then
echo "fix_spelling_pedantic..."
./tools/check_spelling_pedantic.py fix
exit 0
elif [[ "$1" == "docs" ]]; then
echo "generating docs..."
docs/build.sh
exit 0
else
echo "Invalid do_ci.sh target, see ci/README.md for valid targets."
exit 1
fi