forked from chaos-mesh/chaos-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
302 lines (232 loc) · 9.73 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
# Set DEBUGGER=1 to build debug symbols
LDFLAGS = $(if $(DEBUGGER),,-s -w) $(shell ./hack/version.sh)
# SET DOCKER_REGISTRY to change the docker registry
DOCKER_REGISTRY_PREFIX := $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)
DOCKER_BUILD_ARGS := --build-arg HTTP_PROXY=${HTTP_PROXY} --build-arg HTTPS_PROXY=${HTTPS_PROXY} --build-arg UI=${UI} --build-arg SWAGGER=${SWAGGER}
GOVER_MAJOR := $(shell go version | sed -E -e "s/.*go([0-9]+)[.]([0-9]+).*/\1/")
GOVER_MINOR := $(shell go version | sed -E -e "s/.*go([0-9]+)[.]([0-9]+).*/\2/")
GO111 := $(shell [ $(GOVER_MAJOR) -gt 1 ] || [ $(GOVER_MAJOR) -eq 1 ] && [ $(GOVER_MINOR) -ge 11 ]; echo $$?)
IMAGE_TAG := $(if $(IMAGE_TAG),$(IMAGE_TAG),latest)
ROOT=$(shell pwd)
OUTPUT_BIN=$(ROOT)/output/bin
KUSTOMIZE_BIN=$(OUTPUT_BIN)/kustomize
KUBEBUILDER_BIN=$(OUTPUT_BIN)/kubebuilder
KUBECTL_BIN=$(OUTPUT_BIN)/kubectl
HELM_BIN=$(OUTPUT_BIN)/helm
ifeq ($(GO111), 1)
$(error Please upgrade your Go compiler to 1.11 or higher version)
endif
# Enable GO111MODULE=on explicitly, disable it with GO111MODULE=off when necessary.
export GO111MODULE := on
GOOS := $(if $(GOOS),$(GOOS),"")
GOARCH := $(if $(GOARCH),$(GOARCH),"")
GOENV := GO15VENDOREXPERIMENT="1" CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH)
CGOENV := GO15VENDOREXPERIMENT="1" CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH)
GO := $(GOENV) go
CGO := $(CGOENV) go
GOTEST := TEST_USE_EXISTING_CLUSTER=false NO_PROXY="${NO_PROXY},testhost" go test
SHELL := /usr/bin/env bash
PACKAGE_LIST := go list ./... | grep -vE "chaos-mesh/test|pkg/ptrace|zz_generated|vendor"
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/chaos-mesh/||'
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
FAILPOINT_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|bin)" | xargs $(GOBIN)/failpoint-ctl enable)
FAILPOINT_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|bin)" | xargs $(GOBIN)/failpoint-ctl disable)
BUILD_TAGS ?=
ifeq ($(SWAGGER),1)
BUILD_TAGS += swagger_server
endif
ifeq ($(UI),1)
BUILD_TAGS += ui_server
endif
all: yaml image
build: binary
check: fmt vet boilerplate lint generate yaml tidy
# Run tests
test: failpoint-enable generate manifests test-utils
rm -rf cover.* cover
$(GOTEST) $$($(PACKAGE_LIST)) -coverprofile cover.out.tmp
cat cover.out.tmp | grep -v "_generated.deepcopy.go" > cover.out
@$(FAILPOINT_DISABLE)
test-utils: timer multithread_tracee
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
coverage:
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
# Build chaos-daemon binary
chaosdaemon: generate
$(CGOENV) go build -ldflags '$(LDFLAGS)' -o bin/chaos-daemon ./cmd/chaos-daemon/main.go
# Build manager binary
manager: generate
$(GO) build -ldflags '$(LDFLAGS)' -o bin/chaos-controller-manager ./cmd/controller-manager/*.go
chaosfs: generate
$(GO) build -ldflags '$(LDFLAGS)' -o bin/chaosfs ./cmd/chaosfs/*.go
chaos-dashboard: generate
ifeq ($(SWAGGER),1)
make swagger_spec
endif
ifeq ($(UI),1)
make ui
hack/embed_ui_assets.sh
endif
$(CGO) build -ldflags '$(LDFLAGS)' -tags "${BUILD_TAGS}" -o bin/chaos-dashboard cmd/chaos-dashboard/*.go
swagger_spec:
hack/generate_swagger_spec.sh
yarn_dependencies:
cd ui &&\
yarn install --frozen-lockfile
ui: yarn_dependencies
cd ui &&\
REACT_APP_DASHBOARD_API_URL="" yarn build
binary: chaosdaemon manager chaosfs chaos-dashboard
watchmaker:
$(CGOENV) go build -ldflags '$(LDFLAGS)' -o bin/watchmaker ./cmd/watchmaker/...
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
$(GO) run ./cmd/controller-manager/main.go
# Install CRDs into a cluster
install: manifests
$(KUBECTL_BIN) apply -f manifests/crd.yaml
bash -c '[[ `$(HELM_BIN) version --client --short` == "Client: v2"* ]] && $(HELM_BIN) install helm/chaos-mesh --name=chaos-mesh --namespace=chaos-testing || $(HELM_BIN) install chaos-mesh helm/chaos-mesh --namespace=chaos-testing;'
# Generate manifests e.g. CRD, RBAC etc.
manifests: $(GOBIN)/controller-gen
$< $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Run go fmt against code
fmt: groupimports
$(CGOENV) go fmt ./...
gosec-scan: $(GOBIN)/gosec
$(GOENV) $< ./api/... ./controllers/... ./pkg/... || echo "*** sec-scan failed: known-issues ***"
groupimports: $(GOBIN)/goimports
$< -w -l -local github.com/pingcap/chaos-mesh $$($(PACKAGE_DIRECTORIES))
failpoint-enable: $(GOBIN)/failpoint-ctl
# Converting gofail failpoints...
@$(FAILPOINT_ENABLE)
failpoint-disable: $(GOBIN)/failpoint-ctl
# Restoring gofail failpoints...
@$(FAILPOINT_DISABLE)
# Run go vet against code
vet:
$(CGOENV) go vet ./...
tidy: clean
@echo "go mod tidy"
GO111MODULE=on go mod tidy
git diff -U --exit-code go.mod go.sum
clean:
rm -rf docs/docs.go
boilerplate:
./hack/verify-boilerplate.sh
taily-build:
if [ "$(shell docker ps --filter=name=$@ -q)" = "" ]; then \
docker build -t pingcap/binary ${DOCKER_BUILD_ARGS} .; \
docker run --rm --mount type=bind,source=$(shell pwd),target=/src \
--name $@ -d pingcap/binary tail -f /dev/null; \
fi;
taily-build-clean:
docker kill taily-build && docker rm taily-build || exit 0
image: image-chaos-daemon image-chaos-mesh image-chaos-dashboard image-chaos-fs image-chaos-scripts
ifneq ($(TAILY_BUILD),)
image-binary: taily-build
docker exec -it taily-build make binary
cp -r scripts ./bin
echo -e "FROM scratch\n COPY . /src/bin\n COPY ./scripts /src/scripts" | docker build -t pingcap/binary -f - ./bin
else
image-binary:
docker build -t pingcap/binary ${DOCKER_BUILD_ARGS} .
endif
image-chaos-daemon: image-binary
docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/chaos-daemon:${IMAGE_TAG} ${DOCKER_BUILD_ARGS} images/chaos-daemon
image-chaos-mesh: image-binary
docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/chaos-mesh:${IMAGE_TAG} ${DOCKER_BUILD_ARGS} images/chaos-mesh
image-chaos-fs: image-binary
docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/chaos-fs:${IMAGE_TAG} ${DOCKER_BUILD_ARGS} images/chaosfs
image-chaos-scripts: image-binary
docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/chaos-scripts:${IMAGE_TAG} ${DOCKER_BUILD_ARGS} images/chaos-scripts
image-chaos-dashboard: image-binary
docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/chaos-dashboard:${IMAGE_TAG} ${DOCKER_BUILD_ARGS} images/chaos-dashboard
image-chaos-kernel:
docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/chaos-kernel ${DOCKER_BUILD_ARGS} --build-arg MAKE_JOBS=${MAKE_JOBS} --build-arg MIRROR=${UBUNTU_MIRROR} images/chaos-kernel
docker-push:
docker push "${DOCKER_REGISTRY_PREFIX}pingcap/chaos-mesh:${IMAGE_TAG}"
docker push "${DOCKER_REGISTRY_PREFIX}pingcap/chaos-dashboard:${IMAGE_TAG}"
docker push "${DOCKER_REGISTRY_PREFIX}pingcap/chaos-fs:${IMAGE_TAG}"
docker push "${DOCKER_REGISTRY_PREFIX}pingcap/chaos-daemon:${IMAGE_TAG}"
docker push "${DOCKER_REGISTRY_PREFIX}pingcap/chaos-scripts:${IMAGE_TAG}"
docker-push-chaos-kernel:
docker push "${DOCKER_REGISTRY_PREFIX}pingcap/chaos-kernel:${IMAGE_TAG}"
$(GOBIN)/controller-gen:
$(GO) get sigs.k8s.io/controller-tools/cmd/[email protected]
$(GOBIN)/revive:
$(GO) get github.com/mgechev/[email protected]
$(GOBIN)/failpoint-ctl:
$(GO) get github.com/pingcap/failpoint/[email protected]
$(GOBIN)/goimports:
$(GO) get golang.org/x/tools/cmd/[email protected]
$(GOBIN)/gosec:
$(GO) get github.com/securego/gosec/cmd/[email protected]
lint: $(GOBIN)/revive
@echo "linting"
$< -formatter friendly -config revive.toml $$($(PACKAGE_LIST))
# Generate code
generate: $(GOBIN)/controller-gen
$< object:headerFile=./hack/boilerplate/boilerplate.generatego.txt paths="./..."
yaml: manifests ensure-kustomize
$(KUSTOMIZE_BIN) build config/default > manifests/crd.yaml
# Generate Go files from Chaos Mesh proto files.
proto:
hack/genproto.sh
update-install-script:
hack/update_install_script.sh
e2e-build:
$(GO) build -trimpath -o test/image/e2e/bin/ginkgo github.com/onsi/ginkgo/ginkgo
$(GO) test -c -o ./test/image/e2e/bin/e2e.test ./test/e2e
ifeq ($(NO_BUILD),y)
e2e-docker:
@echo "NO_BUILD=y, skip build for $@"
else
e2e-docker: e2e-build
endif
[ -d test/image/e2e/chaos-mesh ] && rm -r test/image/e2e/chaos-mesh || true
cp -r helm/chaos-mesh test/image/e2e
cp -r manifests test/image/e2e
docker build -t "${DOCKER_REGISTRY_PREFIX}pingcap/chaos-mesh-e2e:${IMAGE_TAG}" test/image/e2e
image-e2e-helper:
docker build -t "${DOCKER_REGISTRY_PREFIX}pingcap/e2e-helper:${IMAGE_TAG}" test/cmd/e2e_helper
ensure-kind:
@echo "ensuring kind"
$(shell ./hack/tools.sh kind)
ensure-kubebuilder:
@echo "ensuring kubebuilder"
$(shell ./hack/tools.sh kubebuilder)
ensure-kustomize:
@echo "ensuring kustomize"
$(shell ./hack/tools.sh kustomize)
ensure-kubectl:
@echo "ensuring kubectl"
$(shell ./hack/tools.sh kubectl)
ensure-all:
@echo "ensuring all"
$(shell ./hack/tools.sh all)
install-local-coverage-tools:
go get github.com/axw/gocov/gocov \
&& go get github.com/AlekSi/gocov-xml \
&& go get -u github.com/matm/gocov-html
.PHONY: all build test install manifests groupimports fmt vet tidy image \
binary docker-push lint generate yaml \
manager chaosfs chaosdaemon chaos-dashboard ensure-all \
dashboard dashboard-server-frontend gosec-scan \
proto