-
Notifications
You must be signed in to change notification settings - Fork 125
/
Makefile
341 lines (267 loc) · 10.9 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
SHELL := /usr/bin/env bash -o pipefail
PROJECT := vpp-agent
VERSION ?= $(shell git describe --always --tags --dirty --match 'v*')
COMMIT ?= $(shell git rev-parse HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILD_DATE ?= $(shell date +%s)
BUILD_HOST ?= $(shell hostname)
BUILD_USER ?= $(shell id -un)
GOPKG := go.ligato.io/vpp-agent/v3
LDFLAGS = -w -s \
-X $(GOPKG)/pkg/version.app=$(PROJECT) \
-X $(GOPKG)/pkg/version.version=$(VERSION) \
-X $(GOPKG)/pkg/version.gitCommit=$(COMMIT) \
-X $(GOPKG)/pkg/version.gitBranch=$(BRANCH) \
-X $(GOPKG)/pkg/version.buildDate=$(BUILD_DATE) \
-X $(GOPKG)/pkg/version.buildUser=$(BUILD_USER) \
-X $(GOPKG)/pkg/version.buildHost=$(BUILD_HOST)
UNAME_OS ?= $(shell uname -s)
UNAME_ARCH ?= $(shell uname -m)
ifndef CACHE_BASE
CACHE_BASE := $(HOME)/.cache/$(PROJECT)
endif
CACHE := $(CACHE_BASE)/$(UNAME_OS)/$(UNAME_ARCH)
CACHE_BIN := $(CACHE)/bin
CACHE_INCLUDE := $(CACHE)/include
CACHE_VERSIONS := $(CACHE)/versions
export PATH := $(abspath $(CACHE_BIN)):$(PATH)
ifndef BUILD_DIR
BUILD_DIR := .build
endif
export GO111MODULE=on
export DOCKER_BUILDKIT=1
include vpp.env
ifeq ($(VPP_VERSION),)
VPP_VERSION=$(VPP_DEFAULT)
endif
VPP_IMG?=$(value VPP_$(VPP_VERSION)_IMAGE)
ifeq ($(UNAME_ARCH), aarch64)
VPP_IMG?=$(subst vpp-base,vpp-base-arm64,$(VPP_IMG))
endif
VPP_BINAPI?=$(value VPP_$(VPP_VERSION)_BINAPI)
SKIP_CHECK?=
ifeq ($(NOSTRIP),)
LDFLAGS += -w -s
endif
ifeq ($(NOTRIM),)
GO_BUILD_ARGS += -trimpath
endif
ifeq ($(BUILDPIE),y)
GO_BUILD_ARGS += -buildmode=pie
LDFLAGS += -extldflags=-Wl,-z,now,-z,relro
endif
ifeq ($(V),1)
GO_BUILD_ARGS += -v
endif
COVER_DIR ?= /tmp
help:
@echo "List of make targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/^[^:]*://g' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT = help
-include scripts/make/buf.make
build: cmd examples
clean: clean-cmd clean-examples
agent: ## Build agent
@echo "# installing agent ${VERSION}"
@go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent
agentctl: ## Build agentctl
@echo "# installing agentctl ${VERSION}"
@go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/agentctl
install: ## Install commands
@echo "# installing ${VERSION}"
go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent
go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent-init
go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/agentctl
cmd: ## Build commands
@echo "# building ${VERSION}"
cd cmd/vpp-agent && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd cmd/vpp-agent-init && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd cmd/agentctl && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
clean-cmd: ## Clean commands
@echo "# cleaning command binaries"
rm -f ./cmd/vpp-agent/vpp-agent
rm -f ./cmd/vpp-agent/vpp-agent-init
rm -f ./cmd/agentctl/agentctl
examples: ## Build examples
@echo "# building examples"
cd examples/customize/custom_api_model && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/customize/custom_vpp_plugin && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/govpp_call && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/grpc_vpp/remote_client && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/grpc_vpp/notifications && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/acl && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/interconnect && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/l2 && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/acl && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/nat && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/rxplacement && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/vpp-l3 && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/kvscheduler/vrf && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/localclient_linux/tap && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/localclient_linux/veth && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/localclient_vpp/nat && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
cd examples/localclient_vpp/plugins && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS}
clean-examples: ## Clean examples
@echo "# cleaning examples"
cd examples/customize/custom_api_model && go clean
cd examples/customize/custom_vpp_plugin && go clean
cd examples/govpp_call && go clean
cd examples/grpc_vpp/remote_client && go clean
cd examples/grpc_vpp/notifications && go clean
cd examples/kvscheduler/acl && go clean
cd examples/kvscheduler/interconnect && go clean
cd examples/kvscheduler/l2 && go clean
cd examples/kvscheduler/acl && go clean
cd examples/kvscheduler/nat && go clean
cd examples/kvscheduler/vpp-l3 && go clean
cd examples/localclient_linux/tap && go clean
cd examples/localclient_linux/veth && go clean
cd examples/localclient_vpp/nat && go clean
cd examples/localclient_vpp/plugins && go clean
purge: ## Purge cached files
go clean -testcache -cache
debug-remote: ## Debug remotely
cd ./cmd/vpp-agent && dlv debug --headless --listen=:2345 --api-version=2 --accept-multiclient
# -------------------------------
# Testing
# -------------------------------
test: ## Run unit tests
@echo "# running unit tests"
go test -tags="${GO_BUILD_TAGS}" ./...
test-cover: ## Run unit tests with coverage
@echo "# running unit tests with coverage"
go test -tags="${GO_BUILD_TAGS}" -covermode=count -coverprofile=${COVER_DIR}/coverage.out ./...
@echo "# coverage data generated into ${COVER_DIR}/coverage.out"
test-cover-html: test-cover
go tool cover -html=${COVER_DIR}/coverage.out -o ${COVER_DIR}/coverage.html
@echo "# coverage report generated into ${COVER_DIR}/coverage.html"
perf: ## Run quick performance test
@echo "# running perf test"
./tests/perf/perf_test.sh grpc-perf 1000
perf-all: ## Run all performance tests
@echo "# running all perf tests"
./tests/perf/run_all.sh
integration-tests: test-tools ## Run integration tests
@echo "# running integration tests"
VPP_IMG=$(VPP_IMG) ./tests/integration/run_integration.sh
e2e-tests: images test-tools ## Run end-to-end tests
@echo "# running end-to-end tests"
VPP_AGENT=prod_vpp_agent ./tests/e2e/e2etest/run_e2e.sh
# -------------------------------
# Code generation
# -------------------------------
checknodiffgenerated: ## Check no diff generated
bash scripts/checknodiffgenerated.sh $(MAKE) generate
generate: generate-proto generate-binapi generate-desc-adapters ## Generate all
generate-proto: protocgengo ## Generate Protobuf files
get-binapi-generators:
go install -mod=readonly go.fd.io/govpp/cmd/binapi-generator
generate-binapi: get-binapi-generators ## Generate Go code for VPP binary API
@echo "# generating VPP binapi"
VPP_BINAPI=$(VPP_BINAPI) ./scripts/genbinapi.sh
verify-binapi: ## Verify generated VPP binary API
@echo "# verifying generated binapi"
docker build -f docker/dev/Dockerfile \
--build-arg VPP_IMG=${VPP_IMG} \
--build-arg VPP_VERSION=${VPP_VERSION} \
--target verify-binapi .
get-desc-adapter-generator:
go install ./plugins/kvscheduler/descriptor-adapter
generate-desc-adapters: get-desc-adapter-generator ## Generate Go code for descriptors
@echo "# generating descriptor adapters"
go generate -x -run=descriptor-adapter ./...
get-bindata:
go get -v github.com/jteeuwen/go-bindata/...
go get -v github.com/elazarl/go-bindata-assetfs/...
bindata: get-bindata
@echo "# generating bindata"
go generate -x -run=go-bindata-assetfs ./...
proto-schema: ## Generate Protobuf schema image
@echo "# generating proto schema"
@$(MAKE) --no-print-directory buf-image
# -------------------------------
# Dependencies
# -------------------------------
dep-install:
@echo "# downloading project's dependencies"
go mod download
dep-update:
@echo "# updating all dependencies"
@echo go mod tidy -v
dep-check:
@echo "# checking dependencies"
@if ! git --no-pager diff go.mod ; then \
echo >&2 "go.mod has uncommitted changes!"; \
exit 1; \
fi
go mod verify
go mod tidy -v
@if ! git --no-pager diff go.mod ; then \
echo >&2 "go mod tidy check failed!"; \
exit 1; \
fi
# -------------------------------
# Linters
# -------------------------------
gotestsumcmd := $(shell command -v gotestsum 2> /dev/null)
test-tools: ## install test tools
ifndef gotestsumcmd
go install gotest.tools/gotestsum@v1.10.1
endif
@env CGO_ENABLED=0 go build -ldflags="-s -w" -o $(BUILD_DIR)/test2json cmd/test2json
LINTER := $(shell command -v golangci-lint --version 2> /dev/null)
get-linters:
ifndef LINTER
@echo "# installing linters"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3
endif
lint: get-linters ## Lint Go code
@echo "# running code analysis"
golangci-lint run
format: ## Format Go code
@echo "# formatting the code"
./scripts/gofmt.sh
MDLINKCHECK := $(shell command -v markdown-link-check 2> /dev/null)
get-linkcheck: ## Check links in Markdown files
ifndef MDLINKCHECK
sudo apt-get update && sudo apt-get install -y npm
npm install -g markdown-link-check@3.6.2
endif
check-links: get-linkcheck
./scripts/check_links.sh
get-yamllint:
pip install --user yamllint
yamllint: get-yamllint ## Lint YAML files
@echo "# linting the yaml files"
yamllint -c .yamllint.yml $(shell git ls-files '*.yaml' '*.yml' | grep -v 'vendor/')
lint-proto: ## Lint Protobuf files
@echo "# linting Protobuf files"
@$(MAKE) --no-print-directory buf-lint
check-proto: lint-proto ## Check proto files for breaking changes
@echo "# checking proto files"
@$(MAKE) --no-print-directory buf-breaking
# -------------------------------
# Images
# -------------------------------
images: dev-image prod-image ## Build all images
dev-image: ## Build developer image
@echo "# building dev image"
IMAGE_TAG=$(IMAGE_TAG) \
VPP_IMG=$(VPP_IMG) VPP_VERSION=$(VPP_VERSION) VPP_BINAPI=$(VPP_BINAPI) \
VERSION=$(VERSION) COMMIT=$(COMMIT) BRANCH=$(BRANCH) \
BUILD_DATE=$(BUILD_DATE) \
./docker/dev/build.sh
prod-image: ## Build production image
@echo "# building prod image"
IMAGE_TAG=$(IMAGE_TAG) VPP_VERSION=$(VPP_VERSION) ./docker/prod/build.sh
.PHONY: help \
agent agentctl build clean install purge \
cmd examples clean-examples \
test test-cover test-cover-html \
generate checknodiffgenerated generate-binapi generate-proto get-binapi-generators \
get-dep dep-install dep-update dep-check \
get-linters lint format lint-proto check-proto \
get-linkcheck check-links \
get-yamllint yamllint \
images dev-image prod-image \
perf perf-all