forked from chaos-mesh/chaos-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (147 loc) · 6.3 KB
/
Makefile
File metadata and controls
180 lines (147 loc) · 6.3 KB
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
# 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 := $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY),localhost:5000)
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 $$?)
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),linux)
GOARCH := $(if $(GOARCH),$(GOARCH),amd64)
GOENV := GO15VENDOREXPERIMENT="1" CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH)
GO := $(GOENV) go
GOTEST := TEST_USE_EXISTING_CLUSTER=false go test
PACKAGE_LIST := go list ./... | grep -vE "pkg/client" | grep -vE "zz_generated"
PACKAGE_DIRECTORIES := $(PACKAGE_LIST) | sed 's|github.com/pingcap/chaos-mesh/||'
FILES := $$(find $$($(PACKAGE_DIRECTORIES)) -name "*.go")
FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'
# 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
all: yaml build image
build: chaosdaemon manager chaosfs dashboard
# Run tests
test: generate fmt vet lint manifests
rm -rf cover.* cover
mkdir -p cover
$(GOTEST) ./api/... ./controllers/... ./pkg/... -coverprofile cover.out.tmp
cat cover.out.tmp | grep -v "_generated.deepcopy.go" > cover.out
gocov convert cover.out > cover.json
gocov-xml < cover.json > cover.xml
gocov-html < cover.json > cover/index.html
rm -rf cover.out cover.out.tmp cover.json
# Build chaos-daemon binary
chaosdaemon: generate fmt vet
$(GO) build -ldflags '$(LDFLAGS)' -o images/chaos-daemon/bin/chaos-daemon ./cmd/chaos-daemon/main.go
# Build manager binary
manager: generate fmt vet
$(GO) build -ldflags '$(LDFLAGS)' -o images/chaos-mesh/bin/chaos-controller-manager ./cmd/controller-manager/*.go
chaosfs: generate fmt vet
$(GO) build -ldflags '$(LDFLAGS)' -o images/chaosfs/bin/chaosfs ./cmd/chaosfs/*.go
dashboard: fmt vet
$(GO) build -ldflags '$(LDFLAGS)' -o images/chaos-dashboard/bin/chaos-dashboard ./cmd/chaos-dashboard/*.go
dashboard-server-frontend:
cd images/chaos-dashboard; yarn install; yarn build
# 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 apply -f manifests/crd.yaml
helm install helm/chaos-mesh --name=chaos-mesh --namespace=chaos-testing
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Run go fmt against code
fmt:
$(GO) fmt ./...
# Run go vet against code
vet:
$(GO) vet ./...
tidy:
@echo "go mod tidy"
GO111MODULE=on go mod tidy
git diff --quiet go.mod go.sum
image: dashboard-server-frontend
docker build -t ${DOCKER_REGISTRY}/pingcap/chaos-daemon images/chaos-daemon
docker build -t ${DOCKER_REGISTRY}/pingcap/chaos-mesh images/chaos-mesh
docker build -t ${DOCKER_REGISTRY}/pingcap/chaos-fs images/chaosfs
cp -R hack images/chaos-scripts
docker build -t ${DOCKER_REGISTRY}/pingcap/chaos-scripts images/chaos-scripts
rm -rf images/chaos-scripts/hack
docker build -t ${DOCKER_REGISTRY}/pingcap/chaos-grafana images/grafana
docker build -t ${DOCKER_REGISTRY}/pingcap/chaos-dashboard images/chaos-dashboard
docker-push:
docker push "${DOCKER_REGISTRY}/pingcap/chaos-mesh:latest"
docker push "${DOCKER_REGISTRY}/pingcap/chaos-fs:latest"
docker push "${DOCKER_REGISTRY}/pingcap/chaos-daemon:latest"
docker push "${DOCKER_REGISTRY}/pingcap/chaos-scripts:latest"
bin/revive:
GO111MODULE="on" go build -o bin/revive github.com/mgechev/revive
lint: bin/revive
@echo "linting"
bin/revive -formatter friendly -config revive.toml $$($(PACKAGE_LIST))
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.4
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
yaml: manifests
kustomize build config/default > manifests/crd.yaml
install-kind:
ifeq (,$(shell which kind))
@echo "installing kind"
GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0
else
@echo "kind has been installed"
endif
install-kubebuilder:
ifeq (,$(shell which kubebuilder))
@echo "installing kubebuilder"
# download kubebuilder and extract it to tmp
curl -sL https://go.kubebuilder.io/dl/2.2.0/$(shell go env GOOS)/$(shell go env GOARCH) | tar -zx -C /tmp/
# move to a long-term location and put it on your path
# (you'll need to set the KUBEBUILDER_ASSETS env var if you put it somewhere else)
sudo mv /tmp/kubebuilder_2.2.0_$(shell go env GOOS)_$(shell go env GOARCH) /usr/local/kubebuilder
export PATH=${PATH}:/usr/local/kubebuilder/bin
else
@echo "kubebuilder has been installed"
endif
install-kustomize:
ifeq (,$(shell which kustomize))
@echo "installing kustomize"
# download kustomize
curl -o /usr/local/kubebuilder/bin/kustomize -sL "https://go.kubebuilder.io/kustomize/$(shell go env GOOS)/$(shell go env GOARCH)"
# set permission
sudo chmod a+x /usr/local/kubebuilder/bin/kustomize
$(shell which kustomize)
else
@echo "kustomize has been installed"
endif
install-test-dependency:
go get -u github.com/jstemmer/go-junit-report \
&& go get github.com/axw/gocov/gocov \
&& go get github.com/AlekSi/gocov-xml \
&& go get github.com/onsi/ginkgo/ginkgo \
&& go get golang.org/x/tools/cmd/cover \
&& go get -u github.com/matm/gocov-html
.PHONY: all build test install manifests fmt vet tidy image \
docker-push lint generate controller-gen yaml \
manager chaosfs chaosdaemon install-kind install-kubebuilder \
install-kustomize install-test-dependency dashboard dashboard-server-frontend