forked from antrea-io/antrea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
344 lines (292 loc) · 12.8 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
SHELL := /bin/bash
# go options
GO ?= go
LDFLAGS :=
GOFLAGS :=
BINDIR ?= $(CURDIR)/bin
GO_FILES := $(shell find . -type d -name '.cache' -prune -o -type f -name '*.go' -print)
GOPATH ?= $$($(GO) env GOPATH)
DOCKER_CACHE := $(CURDIR)/.cache
ANTCTL_BINARY_NAME ?= antctl
.PHONY: all
all: build
include versioning.mk
LDFLAGS += $(VERSION_LDFLAGS)
UNAME_S := $(shell uname -s)
USERID := $(shell id -u)
GRPID := $(shell id -g)
.PHONY: bin
bin:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/...
.PHONY: antrea-agent
antrea-agent:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antrea-agent
.PHONY: antrea-agent-instr-binary
antrea-agent-instr-binary:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) test -tags testbincover -covermode count -coverpkg=github.com/vmware-tanzu/antrea/pkg/... -c -o $(BINDIR)/antrea-agent-coverage $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antrea-agent
.PHONY: antrea-controller
antrea-controller:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antrea-controller
.PHONY: .coverage
.coverage:
mkdir -p $(CURDIR)/.coverage
.PHONY: antrea-controller-instr-binary
antrea-controller-instr-binary:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) test -tags testbincover -covermode count -coverpkg=github.com/vmware-tanzu/antrea/pkg/... -c -o $(BINDIR)/antrea-controller-coverage $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antrea-controller
.PHONY: antrea-cni
antrea-cni:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antrea-cni
.PHONY: antctl-ubuntu
antctl-ubuntu:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antctl
.PHONY: antctl-instr-binary
antctl-instr-binary:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) test -tags testbincover -covermode count -coverpkg=github.com/vmware-tanzu/antrea/pkg/... -c -o $(BINDIR)/antctl-coverage $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antctl
.PHONY: windows-bin
windows-bin:
@mkdir -p $(BINDIR)
GOOS=windows $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antrea-cni \
github.com/vmware-tanzu/antrea/cmd/antrea-agent
.PHONY: test-unit test-integration
ifeq ($(UNAME_S),Linux)
test-unit: .linux-test-unit
test-integration: .linux-test-integration
else ifneq (,$(findstring MSYS_NT-,$(UNAME_S)))
test-unit: .windows-test-unit
test-integration:
$(error Cannot use target 'test-integration' on Windows, but you can run integration tests with 'docker-test-integration')
else
test-unit:
$(error Cannot use target 'test-unit' on OS $(UNAME_S), but you can run unit tests with 'docker-test-unit')
test-integration:
$(error Cannot use target 'test-integration' on a non-Linux OS, but you can run integration tests with 'docker-test-integration')
endif
.PHONY: build
build: build-ubuntu
.PHONY: test
test: golangci
test: build
test: docker-test-unit
test: docker-test-integration
$(DOCKER_CACHE):
@mkdir -p $@/gopath
@mkdir -p $@/gocache
# Since the WORKDIR is mounted from host, the $(id -u):$(id -g) user can access it.
# Inside the docker, the user is nameless and does not have a home directory. This is ok for our use case.
DOCKER_ENV := \
@docker run --rm -u $$(id -u):$$(id -g) \
-e "GOCACHE=/tmp/gocache" \
-e "GOPATH=/tmp/gopath" \
-w /usr/src/github.com/vmware-tanzu/antrea \
-v $(DOCKER_CACHE)/gopath:/tmp/gopath \
-v $(DOCKER_CACHE)/gocache:/tmp/gocache \
-v $(CURDIR):/usr/src/github.com/vmware-tanzu/antrea \
golang:1.15
.PHONY: docker-bin
docker-bin: $(DOCKER_CACHE)
$(DOCKER_ENV) make bin
@chmod -R 0755 $<
.PHONY: docker-windows-bin
docker-windows-bin: $(DOCKER_CACHE)
$(DOCKER_ENV) make windows-bin
.PHONY: docker-test-unit
docker-test-unit: $(DOCKER_CACHE)
@$(DOCKER_ENV) make test-unit
@chmod -R 0755 $<
.PHONY: docker-test-integration
docker-test-integration: .coverage
@echo "===> Building Antrea Integration Test Docker image <==="
ifneq ($(DOCKER_REGISTRY),"")
docker build -t antrea/test -f build/images/test/Dockerfile .
else
docker build --pull -t antrea/test -f build/images/test/Dockerfile .
endif
@docker run --privileged --rm \
-e "GOCACHE=/tmp/gocache" \
-e "GOPATH=/tmp/gopath" \
-e "INCONTAINER=true" \
-w /usr/src/github.com/vmware-tanzu/antrea \
-v $(DOCKER_CACHE)/gopath:/tmp/gopath \
-v $(DOCKER_CACHE)/gocache:/tmp/gocache \
-v $(CURDIR)/.coverage:/usr/src/github.com/vmware-tanzu/antrea/.coverage \
-v $(CURDIR):/usr/src/github.com/vmware-tanzu/antrea:ro \
-v /lib/modules:/lib/modules \
antrea/test test-integration $(USERID) $(GRPID)
.PHONY: docker-tidy
docker-tidy: $(DOCKER_CACHE)
@rm -f go.sum
@$(DOCKER_ENV) $(GO) mod tidy
@rm -f plugins/octant/go.sum
@$(DOCKER_ENV) bash -c "cd plugins/octant && $(GO) mod tidy"
@chmod -R 0755 $<
@chmod 0644 go.sum plugins/octant/go.sum
ANTCTL_BINARIES := antctl-darwin antctl-linux antctl-windows
$(ANTCTL_BINARIES): antctl-%:
@GOOS=$* $(GO) build -o $(BINDIR)/$@ $(GOFLAGS) -ldflags '$(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antctl
@if [[ $@ != *windows ]]; then \
chmod 0755 $(BINDIR)/$@; \
else \
mv $(BINDIR)/$@ $(BINDIR)/$@.exe; \
fi
.PHONY: antctl
antctl: $(ANTCTL_BINARIES)
.PHONY: antctl-release
antctl-release:
@$(GO) build -o $(BINDIR)/$(ANTCTL_BINARY_NAME) $(GOFLAGS) -ldflags '-s -w $(LDFLAGS)' github.com/vmware-tanzu/antrea/cmd/antctl
.PHONY: .linux-test-unit
.linux-test-unit: .coverage
@echo
@echo "==> Running unit tests <=="
$(GO) test -race -coverprofile=.coverage/coverage-unit.txt -covermode=atomic -cover github.com/vmware-tanzu/antrea/cmd/... github.com/vmware-tanzu/antrea/pkg/...
.PHONY: .windows-test-unit
.windows-test-unit:
@echo
@echo "==> Running unit tests <=="
$(GO) test -race github.com/vmware-tanzu/antrea/cmd/... github.com/vmware-tanzu/antrea/pkg/...
.PHONY: tidy
tidy:
@rm -f go.sum
@$(GO) mod tidy
@rm -f plugins/octant/go.sum
@cd plugins/octant && $(GO) mod tidy
.PHONY: .linux-test-integration
.linux-test-integration: .coverage
@echo
@echo "==> Running integration tests <=="
@echo "SOME TESTS WILL FAIL IF NOT RUN AS ROOT!"
$(GO) test -coverpkg=github.com/vmware-tanzu/antrea/pkg/... -coverprofile=.coverage/coverage-integration.txt -covermode=atomic -cover github.com/vmware-tanzu/antrea/test/integration/...
test-tidy:
@echo
@echo "===> Checking go.mod tidiness <==="
@GO=$(GO) $(CURDIR)/hack/tidy-check.sh
@echo "===> Checking octant plugins go.mod tidiness <==="
@GO=$(GO) $(CURDIR)/hack/tidy-check.sh plugins/octant
.PHONY: fmt
fmt:
@echo
@echo "===> Formatting Go files <==="
@gofmt -s -l -w $(GO_FILES)
.golangci-bin:
@echo "===> Installing Golangci-lint <==="
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.32.1
.PHONY: golangci
golangci: .golangci-bin
@echo "===> Running golangci for linux <==="
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci.yml
@echo "===> Running golangci for windows <==="
@GOOS=windows .golangci-bin/golangci-lint run -c .golangci.yml
.PHONY: golangci-fix
golangci-fix: .golangci-bin
@echo "===> Running golangci-fix for linux <==="
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci.yml --fix
@echo "===> Running golangci-fix for windows <==="
@GOOS=windows .golangci-bin/golangci-lint run -c .golangci.yml --fix
.PHONY: lint
lint: .golangci-bin
@echo "===> Running lint for linux <==="
@GOOS=linux .golangci-bin/golangci-lint run -c .golangci-golint.yml
@echo "===> Running lint for windows <==="
@GOOS=windows .golangci-bin/golangci-lint run -c .golangci-golint.yml
.PHONY: clean
clean:
@rm -rf $(BINDIR)
@rm -rf $(DOCKER_CACHE)
@rm -rf .golangci-bin
@rm -rf .coverage
.PHONY: codegen
codegen:
@echo "===> Updating generated code <==="
$(CURDIR)/hack/update-codegen.sh
### Docker images ###
.PHONY: ubuntu
ubuntu:
@echo "===> Building antrea/antrea-ubuntu Docker image <==="
docker build --pull -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.ubuntu .
docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu
docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/antrea-ubuntu
docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION)
# Build bins in a golang container, and build the antrea-ubuntu Docker image.
.PHONY: build-ubuntu
build-ubuntu:
@echo "===> Building Antrea bins and antrea/antrea-ubuntu Docker image <==="
ifneq ($(DOCKER_REGISTRY),"")
docker build -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu .
else
docker build --pull -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu .
endif
docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu
docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/antrea-ubuntu
docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION)
.PHONY: build-windows
build-windows:
@echo "===> Building Antrea bins and antrea/antrea-windows Docker image <==="
ifneq ($(DOCKER_REGISTRY),"")
docker build -t antrea/antrea-windows:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.windows .
else
docker build --pull -t antrea/antrea-windows:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.windows .
endif
docker tag antrea/antrea-windows:$(DOCKER_IMG_VERSION) antrea/antrea-windows
docker tag antrea/antrea-windows:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/antrea-windows
docker tag antrea/antrea-windows:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/antrea-windows:$(DOCKER_IMG_VERSION)
.PHONY: build-ubuntu-coverage
build-ubuntu-coverage:
@echo "===> Building Antrea bins and antrea/antrea-ubuntu-coverage Docker image <==="
ifneq ($(DOCKER_REGISTRY),"")
docker build -t antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.coverage .
else
docker build --pull -t antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.coverage .
endif
docker tag antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu-coverage
.PHONY: manifest
manifest:
@echo "===> Generating dev manifest for Antrea <==="
$(CURDIR)/hack/generate-manifest.sh --mode dev > build/yamls/antrea.yml
$(CURDIR)/hack/generate-manifest.sh --mode dev --ipsec > build/yamls/antrea-ipsec.yml
$(CURDIR)/hack/generate-manifest.sh --mode dev --cloud EKS --encap-mode networkPolicyOnly > build/yamls/antrea-eks.yml
$(CURDIR)/hack/generate-manifest.sh --mode dev --cloud GKE --encap-mode noEncap > build/yamls/antrea-gke.yml
$(CURDIR)/hack/generate-manifest.sh --mode dev --cloud AKS --encap-mode networkPolicyOnly > build/yamls/antrea-aks.yml
$(CURDIR)/hack/generate-manifest-octant.sh --mode dev > build/yamls/antrea-octant.yml
$(CURDIR)/hack/generate-manifest-windows.sh --mode dev > build/yamls/antrea-windows.yml
.PHONY: manifest-coverage
manifest-coverage:
$(CURDIR)/hack/generate-manifest.sh --mode dev --coverage > build/yamls/antrea-coverage.yml
$(CURDIR)/hack/generate-manifest.sh --mode dev --ipsec --coverage > build/yamls/antrea-ipsec-coverage.yml
.PHONY: octant-antrea-ubuntu
octant-antrea-ubuntu:
@echo "===> Building antrea/octant-antrea-ubuntu Docker image <==="
docker build --pull -t antrea/octant-antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.octant.ubuntu .
docker tag antrea/octant-antrea-ubuntu:$(DOCKER_IMG_VERSION) antrea/octant-antrea-ubuntu
docker tag antrea/octant-antrea-ubuntu:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/octant-antrea-ubuntu
docker tag antrea/octant-antrea-ubuntu:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/octant-antrea-ubuntu:$(DOCKER_IMG_VERSION)
.PHONY: verify
verify:
@echo "===> Verifying spellings <==="
$(CURDIR)/hack/verify-spelling.sh
@echo "===> Verifying Table of Contents <==="
$(CURDIR)/hack/verify-toc.sh
@echo "===> Verifying documentation formatting for website <==="
$(CURDIR)/hack/verify-docs-for-website.sh
.PHONY: toc
toc:
@echo "===> Generating Table of Contents for Antrea docs <==="
$(CURDIR)/hack/update-toc.sh
.PHONE: markdownlint
markdownlint:
@echo "===> Running markdownlint <==="
markdownlint -c .markdownlint-config.yml -i CHANGELOG.md -i hack/netpol -i CODE_OF_CONDUCT.md .
.PHONE: markdownlint-fix
markdownlint-fix:
@echo "===> Running markdownlint <==="
markdownlint --fix -c .markdownlint-config.yml -i CHANGELOG.md -i hack/netpol -i CODE_OF_CONDUCT.md .
.PHONY: spelling-fix
spelling-fix:
@echo "===> Updating incorrect spellings <==="
$(CURDIR)/hack/update-spelling.sh