forked from chaos-mesh/chaosd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (114 loc) · 4.38 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
LDFLAGS = $(if $(IMG_LDFLAGS),$(IMG_LDFLAGS),$(if $(DEBUGGER),,-s -w) $(shell ./hack/version.sh))
# 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
BYTEMAN_DIR := byteman-chaos-mesh-download-v4.0.18-0.12
# 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
IMAGE_TAG := $(if $(IMAGE_TAG),$(IMAGE_TAG),latest)
BUILD_TAGS ?=
ifeq ($(SWAGGER),1)
BUILD_TAGS += swagger_server
endif
PACKAGE_LIST := go list ./... | grep -vE "chaos-daemon/test|pkg/ptrace|zz_generated|vendor"
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/chaos-mesh/chaosd/||'
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
ARCH = x86_64
endif
ifeq ($(UNAME_M),amd64)
ARCH = x86_64
endif
ifeq ($(UNAME_M),aarch64)
ARCH = aarch64
endif
ifeq ($(UNAME_M),arm64)
ARCH = aarch64
endif
$(GOBIN)/revive:
$(GO) install github.com/mgechev/[email protected]
$(GOBIN)/goimports:
$(GO) install golang.org/x/tools/cmd/[email protected]
build: binary
binary: swagger_spec chaosd chaos-tools
taily-build:
if [ "$(shell docker ps --filter=name=$@ -q)" = "" ]; then \
docker build -t pingcap/chaos-binary ${DOCKER_BUILD_ARGS} .; \
docker run --rm --mount type=bind,source=$(shell pwd),target=/src \
--name $@ -d pingcap/chaos-binary tail -f /dev/null; \
fi;
taily-build-clean:
docker kill taily-build && docker rm taily-build || exit 0
ifneq ($(TAILY_BUILD),)
image-binary: taily-build image-build-base
docker exec -it taily-build make binary
echo -e "FROM scratch\n COPY . /src/bin\n" | docker build -t pingcap/chaos-binary -f - ./bin
else
image-binary: image-build-base
DOCKER_BUILDKIT=1 docker build -t pingcap/chaos-binary ${DOCKER_BUILD_ARGS} .
endif
chaosd:
$(CGOENV) go build -ldflags '$(LDFLAGS)' -tags "${BUILD_TAGS}" -o bin/chaosd ./cmd/main.go
chaos-tools:
$(CGOENV) go build -o bin/tools/PortOccupyTool tools/PortOccupyTool.go
$(CGOENV) go build -o bin/tools/FileTool tools/file/*.go
ifeq (,$(wildcard bin/tools/stress-ng))
curl -fsSL -o ./bin/tools/stress-ng https://github.com/chaos-mesh/stress-ng/releases/download/v0.14.02/stress-ng-${ARCH}
chmod +x ./bin/tools/stress-ng
endif
ifeq (,$(wildcard bin/tools/byteman))
curl -fsSL -o ${BYTEMAN_DIR}.tar.gz https://mirrors.chaos-mesh.org/${BYTEMAN_DIR}.tar.gz
tar zxvf ${BYTEMAN_DIR}.tar.gz
mv ${BYTEMAN_DIR} ./bin/tools/byteman
endif
ifeq (,$(wildcard bin/tools/memStress))
curl -fsSL -o memStress_v0.3-x86_64-linux-gnu.tar.gz https://github.com/chaos-mesh/memStress/releases/download/v0.3/memStress_v0.3-${ARCH}-linux-gnu.tar.gz
tar zxvf memStress_v0.3-x86_64-linux-gnu.tar.gz
mv memStress ./bin/tools/memStress
endif
swagger_spec:
ifeq ($(SWAGGER),1)
hack/generate_swagger_spec.sh
endif
image-build-base:
DOCKER_BUILDKIT=0 docker build --ulimit nofile=65536:65536 -t pingcap/chaos-build-base ${DOCKER_BUILD_ARGS} images/build-base
image-chaosd: image-binary
docker build -t ${DOCKER_REGISTRY_PREFIX}pingcap/chaosd:${IMAGE_TAG} ${DOCKER_BUILD_ARGS} images/chaosd
check: fmt vet boilerplate lint tidy
# Run go fmt against code
fmt: groupimports
$(CGOENV) go fmt ./...
groupimports: $(GOBIN)/goimports
$< -w -l -local github.com/chaos-mesh/chaosd $$($(PACKAGE_DIRECTORIES))
# Run go vet against code
vet:
$(CGOENV) go vet ./...
lint: $(GOBIN)/revive
@echo "linting"
$< -formatter friendly -config revive.toml $$($(PACKAGE_LIST))
boilerplate:
./hack/verify-boilerplate.sh
tidy:
@echo "go mod tidy"
GO111MODULE=on go mod tidy
git diff -U --exit-code go.mod go.sum
unit-test:
rm -rf cover.* cover
$(GOTEST) $$($(PACKAGE_LIST)) -coverprofile cover.out.tmp
cat cover.out.tmp | grep -v "_generated.deepcopy.go" > cover.out
dummy:
$(CGOENV) go build -ldflags '$(LDFLAGS)' -tags "${BUILD_TAGS}" -o bin/dummy ./test/utilities/dummy.go
integration-test: build dummy
bash test/integration_test/run.sh
.PHONY: all build check fmt vet lint tidy binary chaosd chaos image-binary image-chaosd