forked from chaos-mesh/chaos-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
323 lines (243 loc) · 13.1 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
# If you update this file, please follow
# https://suva.sh/posts/well-documented-makefiles
## --------------------------------------
## General
## --------------------------------------
.DEFAULT_GOAL:=help
# Set DEBUGGER=1 to build debug symbols
export LDFLAGS := $(if $(LDFLAGS),$(LDFLAGS),$(if $(DEBUGGER),,-s -w) $(shell ./hack/version.sh))
export IMAGE_TAG ?= latest
export IMAGE_BUILD ?= 1
ROOT=$(shell pwd)
export IMAGE_BUILD_ENV_BUILD ?= 0
export IMAGE_DEV_ENV_BUILD ?= 0
export GOPROXY := $(if $(GOPROXY),$(GOPROXY),https://proxy.golang.org,direct)
GOENV := CGO_ENABLED=0
CGOENV := CGO_ENABLED=1
GO := $(GOENV) go
CGO := $(CGOENV) go
GOTEST := USE_EXISTING_CLUSTER=false NO_PROXY="$(NO_PROXY),testhost" go test
SHELL := bash
PACKAGE_LIST := echo $$(go list -buildvcs=false ./... | grep -vE "chaos-mesh/test|pkg/ptrace|zz_generated|vendor") $$(cd api && go list -buildvcs=false ./... && cd ../)
export GO_BUILD_CACHE ?= $(ROOT)/.cache/chaos-mesh
BUILD_TAGS ?=
ifeq ($(UI),1)
BUILD_TAGS += ui_server
endif
# See https://github.com/chaos-mesh/chaos-mesh/pull/4004 for more details.
ifeq (,$(findstring local/,$(MAKECMDGOALS)))
# Each branch should have its own image tag for build-env and dev-env
# Use := with ifeq instead of = for performance issues (simply expanded)
ifeq ($(IMAGE_BUILD_ENV_TAG),)
export IMAGE_BUILD_ENV_TAG := $(shell ./hack/env-image-tag.sh build-env)
endif
ifeq ($(IMAGE_DEV_ENV_TAG),)
export IMAGE_DEV_ENV_TAG := $(shell ./hack/env-image-tag.sh dev-env)
endif
endif
BASIC_IMAGE_ENV=IMAGE_DEV_ENV_TAG=$(IMAGE_DEV_ENV_TAG) \
IMAGE_BUILD_ENV_TAG=$(IMAGE_BUILD_ENV_TAG) \
IMAGE_TAG=$(IMAGE_TAG) TARGET_PLATFORM=$(TARGET_PLATFORM) \
GO_BUILD_CACHE=$(GO_BUILD_CACHE)
RUN_IN_DEV_SHELL=$(shell $(BASIC_IMAGE_ENV)\
$(ROOT)/build/get_env_shell.py dev-env)
RUN_IN_BUILD_SHELL=$(shell $(BASIC_IMAGE_ENV)\
$(ROOT)/build/get_env_shell.py build-env)
# See https://github.com/chaos-mesh/chaos-mesh/pull/4004 for more details.
ifeq (,$(findstring local/,$(MAKECMDGOALS)))
# Include generated makefiles.
# These sub makefiles depend on RUN_IN_DEV_SHELL and RUN_IN_BUILD_SHELL, so it should be included after them.
include binary.generated.mk container-image.generated.mk
endif
include local-binary.generated.mk
export CLEAN_TARGETS :=
# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
# The awk commands is responsible to read the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help. Then, if there's a line with ##@ something, that gets pretty-printed as a category.
# More info over the usage of ANSI control characters for terminal formatting: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info over awk command: http://linuxcommand.org/lc3_adv_awk.php
#
# Notice that we have a little modification on the awk command to support slash in the recipe name:
# origin: /^[a-zA-Z_0-9-]+:.*?##/
# modified /^[a-zA-Z_0-9\/\.-]+:.*?##/
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9\/\.-]+:.*?##/ { printf " \033[36m%-21s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Code generation
config: SHELL:=$(RUN_IN_DEV_SHELL)
config: images/dev-env/.dockerbuilt ## Generate CRD manifests with controller-gen
cd ./api ;\
controller-gen crd:ignoreUnexportedFields=true,crdVersions=v1 rbac:roleName=manager-role paths="./..." output:crd:artifacts:config=../config/crd/bases ;\
rm ../helm/chaos-mesh/crds/* && cp ../config/crd/bases/* ../helm/chaos-mesh/crds
chaos-build: SHELL:=$(RUN_IN_DEV_SHELL)
chaos-build: bin/chaos-builder images/dev-env/.dockerbuilt ## Generate codes for CustomResource Kinds under api/v1alpha1
bin/chaos-builder
generate: manifests/crd.yaml generate-ctrl swagger_spec generate-deepcopy chaos-build ## Generate codes for codebase, including CRD manifests, chaosctl GraphQL code generation, chaos mesh controller code generation, deepcopy, swager spec.
generate-ctrl: SHELL:=$(RUN_IN_DEV_SHELL)
generate-ctrl: images/dev-env/.dockerbuilt generate-deepcopy ## Generate GraphQL schema for chaosctl
$(GO) generate ./pkg/ctrl/server
.PHONY: generate-makefile
generate-makefile: ## Generate makefile (binary.generated.mk, container-image.generated.mk)
@$(GO) run ./cmd/generate-makefile
generate-deepcopy: SHELL:=$(RUN_IN_DEV_SHELL)
generate-deepcopy: images/dev-env/.dockerbuilt chaos-build ## Generate deepcopy files for CRD Kind with controller-gen
cd ./api ;\
controller-gen object:headerFile=../hack/boilerplate/boilerplate.generatego.txt paths="./..." ;
install.sh: SHELL:=$(RUN_IN_DEV_SHELL)
install.sh: images/dev-env/.dockerbuilt ## Generate install.sh
./hack/update_install_script.sh
manifests/crd.yaml: SHELL:=$(RUN_IN_DEV_SHELL)
manifests/crd.yaml: config images/dev-env/.dockerbuilt ## Generate the combined CRD manifests
kustomize build config/default > manifests/crd.yaml
proto: SHELL:=$(RUN_IN_DEV_SHELL)
proto: images/dev-env/.dockerbuilt ## Generate .go files from .proto files
for dir in pkg/chaosdaemon pkg/chaoskernel ; do\
protoc -I $$dir/pb $$dir/pb/*.proto -I /usr/local/include --go_out=plugins=grpc:$$dir/pb --go_out=./$$dir/pb ;\
done
swagger_spec: SHELL:=$(RUN_IN_DEV_SHELL)
swagger_spec: images/dev-env/.dockerbuilt ## Generate OpenAPI/Swagger spec for frontend
swag init -g cmd/chaos-dashboard/main.go --output pkg/dashboard/swaggerdocs --pd --parseInternal
##@ Linters, formatters and others
check: generate manifests/crd.yaml vet boilerplate lint tidy install.sh fmt ## Run prerequisite checks for PR
SKYWALKING_EYES_HEADER = /go/bin/license-eye header -c ./.github/.licenserc.yaml
boilerplate: SHELL:=$(RUN_IN_DEV_SHELL)
boilerplate: images/dev-env/.dockerbuilt
$(SKYWALKING_EYES_HEADER) check
boilerplate-fix: SHELL:=$(RUN_IN_DEV_SHELL)
boilerplate-fix: images/dev-env/.dockerbuilt ## Fix boilerplate
$(SKYWALKING_EYES_HEADER) fix
fmt: SHELL:=$(RUN_IN_DEV_SHELL)
fmt: groupimports images/dev-env/.dockerbuilt ## Reformat go files with gofmt and goimports
$(CGO) fmt $$($(PACKAGE_LIST))
gosec-scan: SHELL:=$(RUN_IN_DEV_SHELL)
gosec-scan: images/dev-env/.dockerbuilt
gosec ./api/... ./controllers/... ./pkg/... || echo "*** sec-scan failed: known-issues ***"
groupimports: SHELL:=$(RUN_IN_DEV_SHELL)
groupimports: images/dev-env/.dockerbuilt ## Reformat go files with goimports
find . -type f -name '*.go' -not -path '**/zz_generated.*.go' -not -path './.cache/**' | xargs \
-d $$'\n' -n 10 goimports -w -l -local github.com/chaos-mesh/chaos-mesh
lint: SHELL:=$(RUN_IN_DEV_SHELL)
lint: images/dev-env/.dockerbuilt ## Lint go files with revive
revive -formatter friendly -config revive.toml $$($(PACKAGE_LIST))
tidy: SHELL:=$(RUN_IN_DEV_SHELL)
tidy: images/dev-env/.dockerbuilt ## Run go mod tidy in all submodules
go mod tidy
git diff -U --exit-code go.mod go.sum
cd api; go mod tidy; git diff -U --exit-code go.mod go.sum
cd e2e-test; go mod tidy; git diff -U --exit-code go.mod go.sum
cd e2e-test/cmd/e2e_helper; go mod tidy; git diff -U --exit-code go.mod go.sum
vet: SHELL:=$(RUN_IN_DEV_SHELL)
vet: images/dev-env/.dockerbuilt ## Lint go files with go vet
$(CGOENV) go vet ./...
##@ Common used building targets
all: manifests/crd.yaml image ## Build all CRD yaml manifests and components container images
chaosctl: ## Build chaosctl
$(GO) build -ldflags '$(LDFLAGS)' -o bin/chaosctl ./cmd/chaosctl/*.go
image: image-chaos-daemon image-chaos-mesh image-chaos-dashboard $(if $(DEBUGGER), image-chaos-dlv) ## Build container images for Chaos Mesh components (chaos-controller-manager, chaos-daemon, chaos-dashboard)
ui: pnpm_install_dependencies ## Build the frontend UI of Chaos Dashboard
ifeq (${UI},1)
cd ui &&\
pnpm build
hack/embed_ui_assets.sh
endif
##@ Cleanup
.PHONY: clean
clean: clean-binary clean-image-built ## Cleanup artifacts
rm -rf $(CLEAN_TARGETS)
##@ Tests
CLEAN_TARGETS += cover.out cover.out.tmp
coverage: SHELL:=$(RUN_IN_DEV_SHELL)
coverage: images/dev-env/.dockerbuilt ## Generate coverage report
ifeq ("$(CI)", "1")
@bash <(curl -s https://codecov.io/bash) -f cover.out -t $(CODECOV_TOKEN)
else
mkdir -p cover
gocov convert cover.out > cover.json
gocov-xml < cover.json > cover.xml
gocov-html < cover.json > cover/index.html
endif
GINKGO_FLAGS ?=
PAUSE_IMAGE ?= gcr.io/google-containers/pause:latest
e2e: e2e-build ## Run e2e tests in current kubernetes cluster
./e2e-test/image/e2e/bin/ginkgo ${GINKGO_FLAGS} ./e2e-test/image/e2e/bin/e2e.test -- --e2e-image ghcr.io/chaos-mesh/e2e-helper:${IMAGE_TAG} --pause-image ${PAUSE_IMAGE}
define failpoint-ctl
find $(ROOT)/* -type d | grep -vE "(\.git|bin|\.cache|ui)" | xargs failpoint-ctl $1
endef
failpoint-enable: SHELL:=$(RUN_IN_DEV_SHELL)
failpoint-enable: images/dev-env/.dockerbuilt ## Enable failpoint stub for testing
$(call failpoint-ctl,enable)
failpoint-disable: SHELL:=$(RUN_IN_DEV_SHELL)
failpoint-disable: images/dev-env/.dockerbuilt ## Disable failpoint stub for testing
$(call failpoint-ctl,disable)
test: SHELL:=$(RUN_IN_DEV_SHELL)
test: generate manifests test-utils images/dev-env/.dockerbuilt ## Run unit tests
$(call failpoint-ctl,enable)
CGO_ENABLED=1 $(GOTEST) -p 1 $$($(PACKAGE_LIST)) -coverprofile cover.out.tmp -covermode=atomic
cat cover.out.tmp | grep -v "_generated.deepcopy.go" > cover.out
$(call failpoint-ctl,disable)
##@ Advanced building targets
test-utils: timer multithread_tracee pkg/time/fakeclock/fake_clock_gettime.o pkg/time/fakeclock/fake_gettimeofday.o
timer:
$(GO) build -ldflags '$(LDFLAGS)' -o bin/test/timer ./test/cmd/timer/*.go
multithread_tracee: test/cmd/multithread_tracee/main.c
cc test/cmd/multithread_tracee/main.c -lpthread -O2 -o ./bin/test/multithread_tracee
pnpm_install_dependencies:
ifeq (${UI},1)
cd ui &&\
pnpm install --frozen-lockfile
endif
watchmaker: pkg/time/fakeclock/fake_clock_gettime.o pkg/time/fakeclock/fake_gettimeofday.o
$(CGO) build -ldflags '$(LDFLAGS)' -o bin/watchmaker ./cmd/watchmaker/...
# Build schedule-migration
schedule-migration:
$(GO) build -ldflags '$(LDFLAGS)' -o bin/schedule-migration ./tools/schedule-migration/*.go
schedule-migration.tar.gz: schedule-migration
cp ./bin/schedule-migration ./schedule-migration
cp ./tools/schedule-migration/migrate.sh ./migrate.sh
tar -czvf schedule-migration.tar.gz schedule-migration migrate.sh
rm ./migrate.sh
rm ./schedule-migration
e2e-image: image-e2e-helper ## Build e2e test helper image
enter-buildenv: SHELL:=$(shell $(BASIC_IMAGE_ENV) $(ROOT)/build/get_env_shell.py --interactive build-env)
enter-buildenv: image-build-env
@bash
enter-devenv: SHELL:=$(shell $(BASIC_IMAGE_ENV) $(ROOT)/build/get_env_shell.py --interactive dev-env)
enter-devenv: images/dev-env/.dockerbuilt
@bash
images/chaos-daemon/bin/pause: SHELL:=$(RUN_IN_BUILD_SHELL)
images/chaos-daemon/bin/pause: hack/pause.c images/build-env/.dockerbuilt ## Build binary pause
cc ./hack/pause.c -o images/chaos-daemon/bin/pause
.PHONY: pkg/time/fakeclock/fake_clock_gettime.o
pkg/time/fakeclock/fake_clock_gettime.o: SHELL:=$(RUN_IN_BUILD_SHELL)
pkg/time/fakeclock/fake_clock_gettime.o: pkg/time/fakeclock/fake_clock_gettime.c images/build-env/.dockerbuilt
[[ "$$TARGET_PLATFORM" == "arm64" ]] && CFLAGS="-mcmodel=tiny" ;\
cc -c ./pkg/time/fakeclock/fake_clock_gettime.c -fPIE -O2 -o pkg/time/fakeclock/fake_clock_gettime.o $$CFLAGS
pkg/time/fakeclock/fake_gettimeofday.o: SHELL:=$(RUN_IN_BUILD_SHELL)
pkg/time/fakeclock/fake_gettimeofday.o: pkg/time/fakeclock/fake_gettimeofday.c images/build-env/.dockerbuilt
[[ "$$TARGET_PLATFORM" == "arm64" ]] && CFLAGS="-mcmodel=tiny" ;\
cc -c ./pkg/time/fakeclock/fake_gettimeofday.c -fPIE -O2 -o pkg/time/fakeclock/fake_gettimeofday.o $$CFLAGS
CLEAN_TARGETS += e2e-test/image/e2e/manifests e2e-test/image/e2e/chaos-mesh
e2e-test/image/e2e/manifests: manifests ## Copy CRD manifests to e2e image build directory
rm -rf e2e-test/image/e2e/manifests
cp -r manifests e2e-test/image/e2e
e2e-test/image/e2e/chaos-mesh: helm/chaos-mesh ## Copy helm chart to e2e image build directory
rm -rf e2e-test/image/e2e/chaos-mesh
cp -r helm/chaos-mesh e2e-test/image/e2e
CLEAN_TARGETS+=e2e-test/image/e2e/bin/ginkgo
e2e-test/image/e2e/bin/ginkgo: SHELL:=$(RUN_IN_DEV_SHELL)
e2e-test/image/e2e/bin/ginkgo: images/dev-env/.dockerbuilt
mkdir -p e2e-test/image/e2e/bin
cp /go/bin/ginkgo e2e-test/image/e2e/bin/ginkgo
CLEAN_TARGETS+=e2e-test/image/e2e/bin/e2e.test
e2e-test/image/e2e/bin/e2e.test: SHELL:=$(RUN_IN_DEV_SHELL)
e2e-test/image/e2e/bin/e2e.test: images/dev-env/.dockerbuilt
cd e2e-test && $(GO) test -c -o ./image/e2e/bin/e2e.test ./e2e
e2e-build: e2e-test/image/e2e/bin/ginkgo e2e-test/image/e2e/bin/e2e.test ## Build e2e test binary
bin/chaos-builder: SHELL:=$(RUN_IN_DEV_SHELL)
bin/chaos-builder: images/dev-env/.dockerbuilt
$(CGOENV) go build -ldflags '$(LDFLAGS)' -buildvcs=false -o bin/chaos-builder ./cmd/chaos-builder/...
.PHONY: all image clean test manifests manifests/crd.yaml \
boilerplate tidy groupimports fmt vet lint install.sh schedule-migration \
config proto \
generate generate-deepcopy swagger_spec bin/chaos-builder \
gosec-scan \
failpoint-enable failpoint-disable \