go.ligato.io/vpp-agent/v3@v3.5.0/Makefile (about) 1 SHELL := /usr/bin/env bash -o pipefail 2 3 PROJECT := vpp-agent 4 VERSION ?= $(shell git describe --always --tags --dirty --match 'v*') 5 COMMIT ?= $(shell git rev-parse HEAD) 6 BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) 7 BUILD_DATE ?= $(shell date +%s) 8 BUILD_HOST ?= $(shell hostname) 9 BUILD_USER ?= $(shell id -un) 10 11 GOPKG := go.ligato.io/vpp-agent/v3 12 LDFLAGS = -w -s \ 13 -X $(GOPKG)/pkg/version.app=$(PROJECT) \ 14 -X $(GOPKG)/pkg/version.version=$(VERSION) \ 15 -X $(GOPKG)/pkg/version.gitCommit=$(COMMIT) \ 16 -X $(GOPKG)/pkg/version.gitBranch=$(BRANCH) \ 17 -X $(GOPKG)/pkg/version.buildDate=$(BUILD_DATE) \ 18 -X $(GOPKG)/pkg/version.buildUser=$(BUILD_USER) \ 19 -X $(GOPKG)/pkg/version.buildHost=$(BUILD_HOST) 20 21 UNAME_OS ?= $(shell uname -s) 22 UNAME_ARCH ?= $(shell uname -m) 23 24 ifndef CACHE_BASE 25 CACHE_BASE := $(HOME)/.cache/$(PROJECT) 26 endif 27 CACHE := $(CACHE_BASE)/$(UNAME_OS)/$(UNAME_ARCH) 28 CACHE_BIN := $(CACHE)/bin 29 CACHE_INCLUDE := $(CACHE)/include 30 CACHE_VERSIONS := $(CACHE)/versions 31 32 export PATH := $(abspath $(CACHE_BIN)):$(PATH) 33 34 ifndef BUILD_DIR 35 BUILD_DIR := .build 36 endif 37 38 export GO111MODULE=on 39 export DOCKER_BUILDKIT=1 40 41 include vpp.env 42 43 ifeq ($(VPP_VERSION),) 44 VPP_VERSION=$(VPP_DEFAULT) 45 endif 46 47 VPP_IMG?=$(value VPP_$(VPP_VERSION)_IMAGE) 48 ifeq ($(UNAME_ARCH), aarch64) 49 VPP_IMG?=$(subst vpp-base,vpp-base-arm64,$(VPP_IMG)) 50 endif 51 VPP_BINAPI?=$(value VPP_$(VPP_VERSION)_BINAPI) 52 53 SKIP_CHECK?= 54 55 ifeq ($(NOSTRIP),) 56 LDFLAGS += -w -s 57 endif 58 59 ifeq ($(NOTRIM),) 60 GO_BUILD_ARGS += -trimpath 61 endif 62 63 ifeq ($(BUILDPIE),y) 64 GO_BUILD_ARGS += -buildmode=pie 65 LDFLAGS += -extldflags=-Wl,-z,now,-z,relro 66 endif 67 68 ifeq ($(V),1) 69 GO_BUILD_ARGS += -v 70 endif 71 72 COVER_DIR ?= /tmp 73 74 help: 75 @echo "List of make targets:" 76 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/^[^:]*://g' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 77 78 .DEFAULT = help 79 80 -include scripts/make/buf.make 81 82 build: cmd examples 83 84 clean: clean-cmd clean-examples 85 86 agent: ## Build agent 87 @echo "# installing agent ${VERSION}" 88 @go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent 89 90 agentctl: ## Build agentctl 91 @echo "# installing agentctl ${VERSION}" 92 @go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/agentctl 93 94 install: ## Install commands 95 @echo "# installing ${VERSION}" 96 go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent 97 go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/vpp-agent-init 98 go install -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} ./cmd/agentctl 99 100 cmd: ## Build commands 101 @echo "# building ${VERSION}" 102 cd cmd/vpp-agent && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 103 cd cmd/vpp-agent-init && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 104 cd cmd/agentctl && go build -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 105 106 clean-cmd: ## Clean commands 107 @echo "# cleaning command binaries" 108 rm -f ./cmd/vpp-agent/vpp-agent 109 rm -f ./cmd/vpp-agent/vpp-agent-init 110 rm -f ./cmd/agentctl/agentctl 111 112 examples: ## Build examples 113 @echo "# building examples" 114 cd examples/customize/custom_api_model && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 115 cd examples/customize/custom_vpp_plugin && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 116 cd examples/govpp_call && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 117 cd examples/grpc_vpp/remote_client && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 118 cd examples/grpc_vpp/notifications && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 119 cd examples/kvscheduler/acl && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 120 cd examples/kvscheduler/interconnect && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 121 cd examples/kvscheduler/l2 && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 122 cd examples/kvscheduler/acl && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 123 cd examples/kvscheduler/nat && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 124 cd examples/kvscheduler/rxplacement && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 125 cd examples/kvscheduler/vpp-l3 && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 126 cd examples/kvscheduler/vrf && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 127 cd examples/localclient_linux/tap && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 128 cd examples/localclient_linux/veth && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 129 cd examples/localclient_vpp/nat && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 130 cd examples/localclient_vpp/plugins && go build -tags="${GO_BUILD_TAGS}" ${GO_BUILD_ARGS} 131 132 clean-examples: ## Clean examples 133 @echo "# cleaning examples" 134 cd examples/customize/custom_api_model && go clean 135 cd examples/customize/custom_vpp_plugin && go clean 136 cd examples/govpp_call && go clean 137 cd examples/grpc_vpp/remote_client && go clean 138 cd examples/grpc_vpp/notifications && go clean 139 cd examples/kvscheduler/acl && go clean 140 cd examples/kvscheduler/interconnect && go clean 141 cd examples/kvscheduler/l2 && go clean 142 cd examples/kvscheduler/acl && go clean 143 cd examples/kvscheduler/nat && go clean 144 cd examples/kvscheduler/vpp-l3 && go clean 145 cd examples/localclient_linux/tap && go clean 146 cd examples/localclient_linux/veth && go clean 147 cd examples/localclient_vpp/nat && go clean 148 cd examples/localclient_vpp/plugins && go clean 149 150 purge: ## Purge cached files 151 go clean -testcache -cache ./... 152 153 debug-remote: ## Debug remotely 154 cd ./cmd/vpp-agent && dlv debug --headless --listen=:2345 --api-version=2 --accept-multiclient 155 156 # ------------------------------- 157 # Testing 158 # ------------------------------- 159 160 test: ## Run unit tests 161 @echo "# running unit tests" 162 go test -tags="${GO_BUILD_TAGS}" ./... 163 164 test-cover: ## Run unit tests with coverage 165 @echo "# running unit tests with coverage" 166 go test -tags="${GO_BUILD_TAGS}" -covermode=count -coverprofile=${COVER_DIR}/coverage.out ./... 167 @echo "# coverage data generated into ${COVER_DIR}/coverage.out" 168 169 test-cover-html: test-cover 170 go tool cover -html=${COVER_DIR}/coverage.out -o ${COVER_DIR}/coverage.html 171 @echo "# coverage report generated into ${COVER_DIR}/coverage.html" 172 173 perf: ## Run quick performance test 174 @echo "# running perf test" 175 ./tests/perf/perf_test.sh grpc-perf 1000 176 177 perf-all: ## Run all performance tests 178 @echo "# running all perf tests" 179 ./tests/perf/run_all.sh 180 181 integration-tests: test-tools ## Run integration tests 182 @echo "# running integration tests" 183 VPP_IMG=$(VPP_IMG) ./tests/integration/run_integration.sh 184 185 e2e-tests: images test-tools ## Run end-to-end tests 186 @echo "# running end-to-end tests" 187 VPP_AGENT=prod_vpp_agent ./tests/e2e/e2etest/run_e2e.sh 188 189 # ------------------------------- 190 # Code generation 191 # ------------------------------- 192 193 checknodiffgenerated: ## Check no diff generated 194 bash scripts/checknodiffgenerated.sh $(MAKE) generate 195 196 generate: generate-proto generate-binapi generate-desc-adapters ## Generate all 197 198 generate-proto: protocgengo ## Generate Protobuf files 199 200 get-binapi-generators: 201 go install -mod=readonly go.fd.io/govpp/cmd/binapi-generator 202 203 generate-binapi: get-binapi-generators ## Generate Go code for VPP binary API 204 @echo "# generating VPP binapi" 205 VPP_BINAPI=$(VPP_BINAPI) ./scripts/genbinapi.sh 206 207 verify-binapi: ## Verify generated VPP binary API 208 @echo "# verifying generated binapi" 209 docker build -f docker/dev/Dockerfile \ 210 --build-arg VPP_IMG=${VPP_IMG} \ 211 --build-arg VPP_VERSION=${VPP_VERSION} \ 212 --target verify-binapi . 213 214 get-desc-adapter-generator: 215 go install ./plugins/kvscheduler/descriptor-adapter 216 217 generate-desc-adapters: get-desc-adapter-generator ## Generate Go code for descriptors 218 @echo "# generating descriptor adapters" 219 go generate -x -run=descriptor-adapter ./... 220 221 get-bindata: 222 go get -v github.com/jteeuwen/go-bindata/... 223 go get -v github.com/elazarl/go-bindata-assetfs/... 224 225 bindata: get-bindata 226 @echo "# generating bindata" 227 go generate -x -run=go-bindata-assetfs ./... 228 229 proto-schema: ## Generate Protobuf schema image 230 @echo "# generating proto schema" 231 @$(MAKE) --no-print-directory buf-image 232 233 # ------------------------------- 234 # Dependencies 235 # ------------------------------- 236 237 dep-install: 238 @echo "# downloading project's dependencies" 239 go mod download 240 241 dep-update: 242 @echo "# updating all dependencies" 243 @echo go mod tidy -v 244 245 dep-check: 246 @echo "# checking dependencies" 247 @if ! git --no-pager diff go.mod ; then \ 248 echo >&2 "go.mod has uncommitted changes!"; \ 249 exit 1; \ 250 fi 251 go mod verify 252 go mod tidy -v 253 @if ! git --no-pager diff go.mod ; then \ 254 echo >&2 "go mod tidy check failed!"; \ 255 exit 1; \ 256 fi 257 258 # ------------------------------- 259 # Linters 260 # ------------------------------- 261 262 gotestsumcmd := $(shell command -v gotestsum 2> /dev/null) 263 264 test-tools: ## install test tools 265 ifndef gotestsumcmd 266 go install gotest.tools/gotestsum@v1.8.1 267 endif 268 @env CGO_ENABLED=0 go build -ldflags="-s -w" -o $(BUILD_DIR)/test2json cmd/test2json 269 270 LINTER := $(shell command -v golangci-lint --version 2> /dev/null) 271 272 get-linters: 273 ifndef LINTER 274 @echo "# installing linters" 275 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.50.1 276 endif 277 278 lint: get-linters ## Lint Go code 279 @echo "# running code analysis" 280 golangci-lint run 281 282 format: ## Format Go code 283 @echo "# formatting the code" 284 ./scripts/gofmt.sh 285 286 MDLINKCHECK := $(shell command -v markdown-link-check 2> /dev/null) 287 288 get-linkcheck: ## Check links in Markdown files 289 ifndef MDLINKCHECK 290 sudo apt-get update && sudo apt-get install -y npm 291 npm install -g markdown-link-check@3.6.2 292 endif 293 294 check-links: get-linkcheck 295 ./scripts/check_links.sh 296 297 get-yamllint: 298 pip install --user yamllint 299 300 yamllint: get-yamllint ## Lint YAML files 301 @echo "# linting the yaml files" 302 yamllint -c .yamllint.yml $(shell git ls-files '*.yaml' '*.yml' | grep -v 'vendor/') 303 304 lint-proto: ## Lint Protobuf files 305 @echo "# linting Protobuf files" 306 @$(MAKE) --no-print-directory buf-lint 307 308 check-proto: lint-proto ## Check proto files for breaking changes 309 @echo "# checking proto files" 310 @$(MAKE) --no-print-directory buf-breaking 311 312 # ------------------------------- 313 # Images 314 # ------------------------------- 315 316 images: dev-image prod-image ## Build all images 317 318 dev-image: ## Build developer image 319 @echo "# building dev image" 320 IMAGE_TAG=$(IMAGE_TAG) \ 321 VPP_IMG=$(VPP_IMG) VPP_VERSION=$(VPP_VERSION) VPP_BINAPI=$(VPP_BINAPI) \ 322 VERSION=$(VERSION) COMMIT=$(COMMIT) BRANCH=$(BRANCH) \ 323 BUILD_DATE=$(BUILD_DATE) \ 324 ./docker/dev/build.sh 325 326 prod-image: ## Build production image 327 @echo "# building prod image" 328 IMAGE_TAG=$(IMAGE_TAG) VPP_VERSION=$(VPP_VERSION) ./docker/prod/build.sh 329 330 331 .PHONY: help \ 332 agent agentctl build clean install purge \ 333 cmd examples clean-examples \ 334 test test-cover test-cover-html \ 335 generate checknodiffgenerated generate-binapi generate-proto get-binapi-generators \ 336 get-dep dep-install dep-update dep-check \ 337 get-linters lint format lint-proto check-proto \ 338 get-linkcheck check-links \ 339 get-yamllint yamllint \ 340 images dev-image prod-image \ 341 perf perf-all