-
Notifications
You must be signed in to change notification settings - Fork 170
/
Makefile
362 lines (296 loc) · 15.6 KB
/
Makefile
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# Copyright 2019 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
#
# 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.
#------------------------------------------------------------------------------
# Variables
#------------------------------------------------------------------------------
SHELL := /bin/bash
BINDIR := bin
IMG="gcr.io/cloudesf-testing/gcpproxy-prow"
TAG := $(shell date +v%Y%m%d)-$(shell git describe --tags --always)
K8S := master
CPP_PROTO_FILES = $(shell find . -type f \
-regex "./\(src\|api\)/.*[.]\(h\|cc\|proto\)" \
-not -path "./vendor/*")
GOFILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./src/go/proto/*")
GODIRS = $(shell go list -f '{{.Dir}}' ./... \
| grep -vFf <(go list -f '{{.Dir}}' ./vendor/...))
#-----------------------------------------------------------------------------
# Target: build
# ----------------------------------------------------------------------------
$(BINDIR):
@mkdir -p $(BINDIR)
.PHONY: build build-envoy build-envoy build-envoy-debug build-grpc-echo build-grpc-bookstore build-grpc-interop upload-e2e-client-binaries
build: format
@echo "--> building"
@go build ./src/go/...
@go build ./tests...
@go build -o bin/configmanager ./src/go/configmanager/main/server.go
@go build -o bin/bootstrap ./src/go/bootstrap/ads/main/main.go
@go build -o bin/gcsrunner ./src/go/gcsrunner/main/runner.go
@go build -o bin/echo/server ./tests/endpoints/echo/server/app.go
build-msan: format
@echo "--> building"
@go build -msan ./src/go/...
@go build -msan ./tests...
@go build -msan -o bin/configmanager ./src/go/configmanager/main/server.go
@go build -msan -o bin/bootstrap ./src/go/bootstrap/ads/main/main.go
@go build -msan -o bin/gcsrunner ./src/go/gcsrunner/main/runner.go
@go build -msan -o bin/echo/server ./tests/endpoints/echo/server/app.go
build-race: format
@echo "--> building"
@go build -race ./src/go/...
@go build -race ./tests...
@go build -race -o bin/configmanager ./src/go/configmanager/main/server.go
@go build -race -o bin/bootstrap ./src/go/bootstrap/ads/main/main.go
@go build -race -o bin/gcsrunner ./src/go/gcsrunner/main/runner.go
@go build -race -o bin/echo/server ./tests/endpoints/echo/server/app.go
build-envoy-asan:
@echo "--> building envoy (compilation_mode=fastbuild)"
bazelisk build --config=clang-asan //src/envoy:envoy
@cp -f bazel-bin/src/envoy/envoy bin/
build-envoy-tsan:
@echo "--> building envoy (compilation_mode=fastbuild)"
bazelisk build --config=clang-tsan //src/envoy:envoy
@cp -f bazel-bin/src/envoy/envoy bin/
build-envoy:
@echo "--> building envoy (compilation_mode=release)"
bazelisk build --config=clang-release //src/envoy:envoy
@cp -f bazel-bin/src/envoy/envoy bin/
build-envoy-debug:
@echo "--> building envoy (compilation_mode=debug)"
bazelisk build --config=debug //src/envoy:envoy
@cp -f bazel-bin/src/envoy/envoy bin/
build-grpc-echo:
@echo "--> building grpc-echo"
@bazelisk build //tests/endpoints/grpc_echo:grpc-test-client
@bazelisk build //tests/endpoints/grpc_echo:grpc-test-server
@bazelisk build //tests/endpoints/grpc_echo:grpc-test_descriptor
@cp -f bazel-bin/tests/endpoints/grpc_echo/grpc-test-client bin/grpc_echo_client
@cp -f bazel-bin/tests/endpoints/grpc_echo/grpc-test-server bin/grpc_echo_server
@cp -f bazel-bin/tests/endpoints/grpc_echo/grpc-test.descriptor tests/endpoints/grpc_echo/proto/api_descriptor.pb
build-grpc-bookstore:
@echo "--> building bookstore-grpc"
@bazelisk build tests/endpoints/bookstore_grpc/proto:bookstore_descriptor
@cp -f bazel-bin/tests/endpoints/bookstore_grpc/proto/bookstore.descriptor tests/endpoints/bookstore_grpc/proto/api_descriptor.pb
@bazelisk build @com_google_protobuf//:protoc
@bazel-bin/external/com_google_protobuf_protoc_linux_x86_64/protoc.exe -I tests/endpoints/bookstore_grpc/proto/v1 -I bazel-esp-v2/external/com_google_protobuf/src -I bazel-esp-v2/external/com_google_googleapis \
-I tests/endpoints/bookstore_grpc/proto/ tests/endpoints/bookstore_grpc/proto/v1/bookstore.proto --go_out=plugins=grpc:tests/endpoints/bookstore_grpc/proto/v1/
@bazel-bin/external/com_google_protobuf_protoc_linux_x86_64/protoc.exe -I tests/endpoints/bookstore_grpc/proto/v2 -I bazel-esp-v2/external/com_google_protobuf/src -I bazel-esp-v2/external/com_google_googleapis \
-I tests/endpoints/bookstore_grpc/proto/ tests/endpoints/bookstore_grpc/proto/v2/bookstore_v2.proto --go_out=plugins=grpc:tests/endpoints/bookstore_grpc/proto/v2/
build-grpc-interop:
@echo "--> building the grpc-interop-test client and server"
@bazelisk build @com_github_grpc_grpc//test/cpp/interop:interop_client
@bazelisk build @com_github_grpc_grpc//test/cpp/interop:metrics_client
@bazelisk build @com_github_grpc_grpc//test/cpp/interop:interop_server
@bazelisk build @com_github_grpc_grpc//test/cpp/interop:stress_test
@cp -f bazel-bin/external/com_github_grpc_grpc/test/cpp/interop/interop_client bin/
@cp -f bazel-bin/external/com_github_grpc_grpc/test/cpp/interop/metrics_client bin/
@cp -f bazel-bin/external/com_github_grpc_grpc/test/cpp/interop/interop_server bin/
@cp -f bazel-bin/external/com_github_grpc_grpc/test/cpp/interop/stress_test bin/
# This target is to upload e2e client binaries so once they get updated, please
# upload the binaries to GCS buckets by this target.
# The execution environment of prow image may be incompatible with your local
# building environment which fails the client binaries so you may have to make
# this target in the prow image, for which you can find the latest version under
# https://github.com/GoogleCloudPlatform/oss-test-infra/blob/master/prow/prowjobs/GoogleCloudPlatform/esp-v2/esp-v2.yaml
upload-e2e-client-binaries: build-grpc-echo build-grpc-interop
@mkdir -p /tmp/apiproxy-test-presubmit-binaries/
@cp -n bin/interop_client /tmp/apiproxy-test-presubmit-binaries/interop_client
@cp -n bin/metrics_client /tmp/apiproxy-test-presubmit-binaries/metrics_client
@cp -n bin/stress_test /tmp/apiproxy-test-presubmit-binaries/stress_test
@cp -n bin/grpc_echo_client /tmp/apiproxy-test-presubmit-binaries/grpc_echo_client
@cp -n tests/endpoints/grpc_echo/proto/api_descriptor.pb /tmp/apiproxy-test-presubmit-binaries/api_descriptor.pb
@gsutil cp -Z -r /tmp/apiproxy-test-presubmit-binaries/* "gs://apiproxy-testing-presubmit-binaries/"
#-----------------------------------------------------------------------------
# Target: go test
# ----------------------------------------------------------------------------
.PHONY: test test-debug test-envoy
test: format
@echo "--> running unit tests"
@go test ./src/go/...
# The unit tests under src/go/serviceconfig reads/writes the global variable
# util.CallGoogleapis(no mutex proctection) plus the function code reads it,
# so it is easy to get into race condition when multiple test runs
# and skip them for race detection.
@go test -race $(shell go list ./src/go/... | grep -v serviceconfig) -count=1
@go test -msan ./src/go/...
@python3 -m unittest tests/start_proxy/start_proxy_test.py
@python3 -m unittest tests/start_proxy/env_start_proxy_test.py
test-debug: format
@echo "--> running unit tests"
@go test -v ./src/go/... --logtostderr
test-envoy: clang-format
@echo "--> running envoy's unit tests"
bazelisk test //src/...
test-envoy-asan: clang-format
@echo "--> running envoy's unit tests (asan)"
ASAN_SYMBOLIZER_PATH=$(which llvm-symbolizer-14) bazelisk test --config=clang-asan --test_output=errors //src/...
test-envoy-tsan: clang-format
@echo "--> running envoy's unit tests (tsan)"
ASAN_SYMBOLIZER_PATH=$(which llvm-symbolizer-14) bazelisk test --config=clang-tsan --test_output=errors //src/...
.PHONY: integration-test-run-sequential integration-test-run-parallel integration-test integration-test-asan integration-test-tsan integration-debug
integration-test-run-sequential:
@echo "--> running integration tests"
# Default timeout for go test is 10 minutes. Our test suite takes a little longer...
# logtostderr will cause all glogs in the test framework to print to the console (not too much bloat)
@go test -timeout 20m ./tests/endpoints/...
@go test -timeout 20m ./tests/env/... --logtostderr
@go test -timeout 20m ./tests/utils/... --logtostderr
@go test -v -timeout 80m -parallel 1 ./tests/integration_test/... --logtostderr
integration-test-run-parallel:
@echo "--> running integration tests"
# Default timeout for go test is 10 minutes. Our test suite takes a little longer...
# logtostderr will cause all glogs in the test framework to print to the console (not too much bloat)
@go test -timeout 20m ./tests/endpoints/...
@go test -timeout 20m ./tests/env/... --logtostderr
@go test -timeout 20m ./tests/utils/... --logtostderr
@go test -v -timeout 20m ./tests/integration_test/... --logtostderr
integration-test: build build-envoy build-grpc-interop build-grpc-echo integration-test-run-sequential
integration-debug: build build-envoy-debug build-grpc-interop build-grpc-echo
@echo "--> running integration tests and showing debug logs"
@go test -timeout 20m ./tests/endpoints/...
@go test -v -timeout 20m ./tests/env/... --logtostderr
@go test -v -timeout 20m ./tests/utils/... --logtostderr
# debug-components can be set as "all", "configmanager", or "envoy".
@go test -v -timeout 20m ./tests/integration_test/... --debug_components=envoy --logtostderr
integration-test-asan: build-msan build-envoy-asan build-grpc-interop build-grpc-echo integration-test-run-sequential
# next line is to work around issue: https://github.com/google/sanitizers/issues/953
integration-test-tsan: export TSAN_OPTIONS=report_atomic_races=0
integration-test-tsan: build-race build-envoy-tsan build-grpc-interop build-grpc-echo integration-test-run-sequential
#-----------------------------------------------------------------------------
# Target: dependencies
#-----------------------------------------------------------------------------
.PHONY: depend.update depend.install
depend.update:
@echo "--> generating go proto files"
./api/scripts/go_proto_gen.sh
depend.install: tools.beautysh
@echo "--> generating go proto files"
./api/scripts/go_proto_gen.sh
depend.install.endpoints:
@echo "--> updating dependencies from package.json"
@npm install ./tests/endpoints/bookstore/ --no-package-lock
#----------------------------------------------------------------------------
# Target: tools
#----------------------------------------------------------------------------
.PHONY: tools tools.goimports tools.golint tools.govet \
tools.buildifier tools.beautysh
tools: tools.goimports tools.golint tools.govet tools.buildifier
tools.goimports:
@command -v goimports >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing goimports"; \
go install golang.org/x/tools/cmd/goimports@latest; \
fi
tools.govet:
@go tool vet 2>/dev/null ; if [ $$? -eq 3 ]; then \
echo "--> installing govet"; \
go install golang.org/x/tools/cmd/vet@latest; \
fi
tools.golint:
@command -v golint >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing golint"; \
go install golang.org/x/lint/golint@latest; \
fi
tools.buildifier:
@command -v buildifier >/dev/null ; if [ $$? -ne 0 ]; then \
echo "--> installing buildifier"; \
go install github.com/bazelbuild/buildtools/buildifier@latest; \
fi
# beautysh is already installed in the newer prow image with pipx
# TODO(shuoyang2016): remove this after we switch prow to the
# latest version.
tools.beautysh:
@command -v pipx >/dev/null;\
PIPX_INSTALLED=$$?;\
command -v beautysh >/dev/null; if [ $$? -ne 0 ] && [ $${PIPX_INSTALLED} -ne 0 ]; then \
echo "--> installing beautysh"; \
pip3 install --user beautysh; \
fi
.PHONY: clean
clean:
@echo "--> cleaning compiled objects and binaries"
@go clean -tags netgo -i ./...
@rm -rf $(BINDIR)/*
@rm -rf bazel-*
# Should always be called before pushing changes.
.PHONY: check
check: format.check vet lint
.PHONY: spelling.check
spelling.check:
@echo "--> checking spelling"
@third_party/tools/spelling/check_spelling.sh check
.PHONY: spelling.fix
spelling.fix:
@echo "--> fixing spelling"
@third_party/tools/spelling/check_spelling.sh fix
.PHONY: format
format: tools.goimports tools.buildifier
@echo "--> formatting code with 'goimports' tool"
@goimports -w -l $(GOFILES)
@echo "--> formatting BUILD files with 'buildifier' tool"
@buildifier -r WORKSPACE ./src/ ./api/
@echo "--> formatting examples"
./scripts/format-examples.sh
@make spelling.fix
.PHONY: clang-format shell-format
clang-format:
@echo "--> formatting code with 'clang-format' tool"
@echo $(CPP_PROTO_FILES) | xargs clang-format-14 -i
shell-format: tools.beautysh
@command -v pipx >/dev/null;\
PIPX_INSTALLED=$$?;\
echo "--> formatting shell scripts with 'beautysh' tool"; \
if [ $${PIPX_INSTALLED} -ne 0 ]; then \
git ls-files "*.sh" | xargs ${HOME}/.local/bin/beautysh -i 2; \
else git ls-files "*.sh" | xargs pipx run beautysh -i 2; \
fi
.PHONY: format.check
format.check: tools.goimports
@echo "--> checking code formatting with 'goimports' tool"
@goimports -l $(GOFILES) | sed -e "s/^/\?\t/" | tee >(test -z)
@make spelling.check
test-ssl-files:
@openssl genrsa -out tests/env/testdata/downstream_client.key 2048
@openssl req -nodes -new -x509 -sha256 -days 1825 -config tests/env/testdata/cert.conf -extensions 'req_ext' -key tests/env/testdata/downstream_client.key -out tests/env/testdata/downstream_client.crt
@openssl genrsa -out tests/env/testdata/proxy.key 2048
@openssl req -nodes -new -x509 -sha256 -days 1825 -config tests/env/testdata/cert.conf -extensions 'req_ext' -key tests/env/testdata/proxy.key -out tests/env/testdata/proxy.crt
@openssl genrsa -out tests/env/testdata/server.key 2048
@openssl genrsa -out tests/env/testdata/mismatch.key 2048
@openssl req -nodes -new -x509 -sha256 -days 1825 -config tests/env/testdata/cert.conf -extensions 'req_ext' -key tests/env/testdata/mismatch.key -out tests/env/testdata/mismatch.crt
@openssl req -nodes -new -x509 -sha256 -days 1825 -config tests/env/testdata/cert.conf -extensions 'req_ext' -key tests/env/testdata/server.key -out tests/env/testdata/server.crt
# The client.crt and client.key are for upstream client certs.
# https://github.com/GoogleCloudPlatform/esp-v2/blob/f963f0318a8981e5713b99652f62438ca174fe4b/docker/generic/start_proxy.py#L188
@cp tests/env/testdata/server.crt tests/env/testdata/client.crt
@cp tests/env/testdata/server.key tests/env/testdata/client.key
.PHONY: vet
vet: tools.govet
@echo "--> checking code correctness with 'go vet' tool"
@go vet ./...
.PHONY: lint
lint: tools.golint
@echo "--> checking code style with 'golint' tool"
@echo $(GODIRS) | xargs -n 1 golint
#-----------------------------------------------------------------------------
# Target : docker
# ----------------------------------------------------------------------------
.PHONY: docker.build-prow docker.push-prow docker.build-configmanager
docker.build-prow:
docker build -f docker/Dockerfile-prow-env --build-arg IMAGE_ARG=$(IMG):$(TAG)-$(K8S) -t $(IMG):$(TAG)-$(K8S) .
docker.push-prow:
docker push $(IMG):$(TAG)-$(K8S)
# bookstore image used in e2e test. Only push when there is changes.
docker.build-bookstore:
docker build -f tests/endpoints/bookstore/bookstore.Dockerfile -t gcr.io/cloudesf-testing/http-bookstore:3 .
docker.push-bookstore:
gcloud docker -- push gcr.io/cloudesf-testing/http-bookstore:3