-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMakefile
253 lines (206 loc) · 9.14 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
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
THEIA_BINARY_NAME ?= theia
GO_VERSION := $(shell head -n 1 build/images/deps/go-version)
GIT_HOOKS := $(shell find hack/git_client_side_hooks -type f -print)
TRIVY_TARGET_IMAGE ?=
GOLANGCI_LINT_VERSION := v1.54.2
GOLANGCI_LINT_BINDIR := $(CURDIR)/.golangci-bin
GOLANGCI_LINT_BIN := $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION)/golangci-lint
DOCKER_BUILD_ARGS = --build-arg GO_VERSION=$(GO_VERSION)
.PHONY: all
all: theia
include versioning.mk
VERSION_LDFLAGS = -X antrea.io/theia/pkg/version.Version=$(VERSION)
VERSION_LDFLAGS += -X antrea.io/theia/pkg/version.GitSHA=$(GIT_SHA)
VERSION_LDFLAGS += -X antrea.io/theia/pkg/version.GitTreeState=$(GIT_TREE_STATE)
VERSION_LDFLAGS += -X antrea.io/theia/pkg/version.ReleaseStatus=$(RELEASE_STATUS)
LDFLAGS += $(VERSION_LDFLAGS)
UNAME_S := $(shell uname -s)
.PHONY: bin
bin:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' antrea.io/theia/plugins/...
.trivy-bin:
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b $@ v0.34.0
check-%:
@: $(if $(value $*),,$(error $* is undefined))
.PHONY: trivy-scan
trivy-scan: .trivy-bin check-TRIVY_TARGET_IMAGE
$(CURDIR)/.trivy-bin/trivy image -c .trivy.yml $(TRIVY_TARGET_IMAGE)
.PHONY: .coverage
.coverage:
mkdir -p $(CURDIR)/.coverage/unit
.PHONY: test-unit
ifeq ($(UNAME_S),Linux)
test-unit: .linux-test-unit
else
test-unit:
$(error Cannot use target 'test-unit' on OS $(UNAME_S), but you can run unit tests with 'docker-test-unit')
endif
.PHONY: test
test: golangci
test: docker-test-unit
$(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/antrea.io/theia \
-v $(DOCKER_CACHE)/gopath:/tmp/gopath \
-v $(DOCKER_CACHE)/gocache:/tmp/gocache \
-v $(CURDIR):/usr/src/antrea.io/theia \
golang:1.21
.PHONY: docker-test-unit
docker-test-unit: $(DOCKER_CACHE)
@$(DOCKER_ENV) make test-unit
@chmod -R 0755 $<
.PHONY: docker-tidy
docker-tidy: $(DOCKER_CACHE)
@rm -f go.sum
@$(DOCKER_ENV) $(GO) mod tidy
.PHONY: check-copyright
check-copyright:
@GO=$(GO) $(CURDIR)/hack/add-license.sh
.PHONY: add-copyright
add-copyright:
@GO=$(GO) $(CURDIR)/hack/add-license.sh --add
.PHONY: .linux-test-unit
.linux-test-unit: .coverage
@echo
@echo "==> Running unit tests <=="
$(GO) test -race -coverpkg=antrea.io/theia/plugins/...,antrea.io/theia/pkg/...,antrea.io/theia/cmd/... \
-coverprofile=.coverage/unit/coverage-unit.txt -covermode=atomic \
antrea.io/theia/plugins/... antrea.io/theia/pkg/... antrea.io/theia/cmd/... \
.PHONY: tidy
tidy:
@rm -f go.sum
@$(GO) mod tidy
test-tidy:
@echo
@echo "===> Checking go.mod tidiness <==="
@GO=$(GO) $(CURDIR)/hack/tidy-check.sh
.PHONY: fmt
fmt:
@echo
@echo "===> Formatting Go files <==="
@gofmt -s -l -w $(GO_FILES)
$(GOLANGCI_LINT_BIN):
@rm -rf $(GOLANGCI_LINT_BINDIR)/* # remove old versions
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION) $(GOLANGCI_LINT_VERSION)
.PHONY: golangci
golangci: $(GOLANGCI_LINT_BIN)
@echo "===> Running golangci (linux) <==="
@GOOS=linux $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml
.PHONY: golangci-fix
golangci-fix: $(GOLANGCI_LINT_BIN)
@echo "===> Running golangci (linux) <==="
@GOOS=linux $(GOLANGCI_LINT_BIN) run -c $(CURDIR)/.golangci.yml --fix
.PHONY: clean
clean:
@rm -rf $(BINDIR)
@rm -rf $(DOCKER_CACHE)
@rm -rf $(GOLANGCI_LINT_BINDIR)
@rm -rf .trivy-bin
.PHONY: codegen
codegen:
@echo "===> Updating generated code <==="
$(CURDIR)/hack/update-codegen.sh
.PHONY: manifest
manifest:
@echo "===> Generating dev manifest for Theia <==="
$(CURDIR)/hack/generate-manifest.sh --mode dev > build/yamls/flow-visibility.yml
.PHONY: verify
verify:
@echo "===> Verifying spellings <==="
GO=$(GO) $(CURDIR)/hack/verify-spelling.sh
@echo "===> Verifying Table of Contents <==="
GO=$(GO) $(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 Theia docs <==="
GO=$(GO) $(CURDIR)/hack/update-toc.sh
.PHONE: markdownlint
markdownlint:
@echo "===> Running markdownlint <==="
markdownlint -c .markdownlint-config.yml -i CHANGELOG/ -i CHANGELOG.md -i CODE_OF_CONDUCT.md .
.PHONE: markdownlint-fix
markdownlint-fix:
@echo "===> Running markdownlint <==="
markdownlint --fix -c .markdownlint-config.yml -i CHANGELOG/ -i CHANGELOG.md -i CODE_OF_CONDUCT.md .
.PHONY: spelling-fix
spelling-fix:
@echo "===> Updating incorrect spellings <==="
$(CURDIR)/hack/update-spelling.sh
.PHONY: clickhouse-monitor
clickhouse-monitor:
@echo "===> Building antrea/theia-clickhouse-monitor Docker image <==="
docker build --pull -t antrea/theia-clickhouse-monitor:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.clickhouse-monitor.ubuntu $(DOCKER_BUILD_ARGS) .
docker tag antrea/theia-clickhouse-monitor:$(DOCKER_IMG_VERSION) antrea/theia-clickhouse-monitor
docker tag antrea/theia-clickhouse-monitor:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-clickhouse-monitor
docker tag antrea/theia-clickhouse-monitor:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-clickhouse-monitor:$(DOCKER_IMG_VERSION)
.PHONY: clickhouse-monitor-plugin
clickhouse-monitor-plugin:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -cover -ldflags '$(LDFLAGS)' antrea.io/theia/plugins/clickhouse-monitor
.PHONY: theia-manager
theia-manager:
@echo "===> Building antrea/theia-manager Docker image <==="
docker build --pull -t antrea/theia-manager:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.theia-manager.ubuntu $(DOCKER_BUILD_ARGS) .
docker tag antrea/theia-manager:$(DOCKER_IMG_VERSION) antrea/theia-manager
docker tag antrea/theia-manager:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-manager
docker tag antrea/theia-manager:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-manager:$(DOCKER_IMG_VERSION)
.PHONY: theia-manager-bin
theia-manager-bin:
@mkdir -p $(BINDIR)
GOOS=linux $(GO) build -o $(BINDIR) $(GOFLAGS) -cover -ldflags '$(LDFLAGS)' antrea.io/theia/cmd/theia-manager
.PHONY: clickhouse-server
clickhouse-server:
@echo "===> Building antrea/theia-clickhouse-server Docker image <==="
docker build --pull -t antrea/theia-clickhouse-server:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.clickhouse-server.ubuntu $(DOCKER_BUILD_ARGS) .
docker tag antrea/theia-clickhouse-server:$(DOCKER_IMG_VERSION) antrea/theia-clickhouse-server
docker tag antrea/theia-clickhouse-server:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-clickhouse-server
docker tag antrea/theia-clickhouse-server:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-clickhouse-server:$(DOCKER_IMG_VERSION)
.PHONY: clickhouse-server-multi-arch
clickhouse-server-multi-arch:
@echo "===> Building antrea/theia-clickhouse-server Docker image <==="
docker buildx build --platform=linux/amd64,linux/arm64 --push --pull -t antrea/theia-clickhouse-server:$(VERSION) -f build/images/Dockerfile.clickhouse-server.ubuntu $(DOCKER_BUILD_ARGS) .
.PHONY: clickhouse-schema-management-plugin
clickhouse-schema-management-plugin:
@mkdir -p $(BINDIR)
GOOS=linux CGO_ENABLED=0 $(GO) build -o $(BINDIR) $(GOFLAGS) -ldflags '$(LDFLAGS)' antrea.io/theia/plugins/clickhouse-schema-management
# Theia currently supports two spark jobs, Throughput Anomaly Detection and Policy Recommendation.
# This Dockerfile helps create unified dockerfile for both the spark jobs.
.PHONY: spark-jobs
spark-jobs:
@echo "===> Building antrea/theia-spark-jobs Docker image <==="
docker build --pull -t antrea/theia-spark-jobs:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.spark-jobs.ubuntu .
docker tag antrea/theia-spark-jobs:$(DOCKER_IMG_VERSION) antrea/theia-spark-jobs
docker tag antrea/theia-spark-jobs:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-spark-jobs
docker tag antrea/theia-spark-jobs:$(DOCKER_IMG_VERSION) projects.registry.vmware.com/antrea/theia-spark-jobs:$(DOCKER_IMG_VERSION)
THEIA_BINARIES := theia-darwin theia-linux theia-windows
$(THEIA_BINARIES): theia-%:
@GOOS=$* $(GO) build -o $(BINDIR)/$@ $(GOFLAGS) -ldflags '$(LDFLAGS)' antrea.io/theia/pkg/theia
@if [[ $@ != *windows ]]; then \
chmod 0755 $(BINDIR)/$@; \
else \
mv $(BINDIR)/$@ $(BINDIR)/[email protected]; \
fi
.PHONY: theia
theia: $(THEIA_BINARIES)
.PHONY: theia-release
theia-release:
@$(GO) build -o $(BINDIR)/$(THEIA_BINARY_NAME) $(GOFLAGS) -ldflags '-s -w $(LDFLAGS)' antrea.io/theia/pkg/theia