vitess.io/vitess@v0.16.2/Makefile (about) 1 # Copyright 2019 The Vitess Authors. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 MAKEFLAGS = -s 16 GIT_STATUS := $(shell git status --porcelain) 17 18 ifndef GOARCH 19 export GOARCH=$(go env GOARCH) 20 endif 21 22 # This is where Go installs binaries when you run `go install`. By default this 23 # is $GOPATH/bin. It is better to try to avoid setting this globally, because 24 # Go will complain if you try to cross-install while this is set. 25 # 26 # GOBIN= 27 28 ifndef GOOS 29 export GOOS=$(go env GOOS) 30 endif 31 32 # GOPATH is the root of the Golang installation. `bin` is nested under here. In 33 # development environments, this is usually $HOME/go. In production and Docker 34 # environments, this is usually /go. 35 ifndef GOPATH 36 export GOPATH=$(go env GOROOT) 37 endif 38 39 # This governs where Vitess binaries are installed during `make install` and 40 # `make cross-install`. Typically for production builds we set this to /vt. 41 # PREFIX= 42 43 export REWRITER=go/vt/sqlparser/rewriter.go 44 45 # Disabled parallel processing of target prerequisites to avoid that integration tests are racing each other (e.g. for ports) and may fail. 46 # Since we are not using this Makefile for compilation, limiting parallelism will not increase build time. 47 .NOTPARALLEL: 48 49 .PHONY: all build install test clean unit_test unit_test_cover unit_test_race integration_test proto proto_banner site_test site_integration_test docker_bootstrap docker_test docker_unit_test java_test reshard_tests e2e_test e2e_test_race minimaltools tools generate_ci_workflows 50 51 all: build 52 53 # Set a custom value for -p, the number of packages to be built/tested in parallel. 54 # This is currently only used by our Travis CI test configuration. 55 # (Also keep in mind that this value is independent of GOMAXPROCS.) 56 ifdef VT_GO_PARALLEL_VALUE 57 export VT_GO_PARALLEL := -p $(VT_GO_PARALLEL_VALUE) 58 endif 59 60 ifdef VT_EXTRA_BUILD_FLAGS 61 export EXTRA_BUILD_FLAGS := $(VT_EXTRA_BUILD_FLAGS) 62 endif 63 64 # This should be the root of the vitess Git directory. 65 ifndef VTROOT 66 export VTROOT=${PWD} 67 endif 68 69 # This is where Go will install binaries in response to `go build`. 70 export VTROOTBIN=${VTROOT}/bin 71 72 # build the vitess binaries with dynamic dependency on libc 73 build-dyn: 74 ifndef NOBANNER 75 echo $$(date): Building source tree 76 endif 77 bash ./build.env 78 go build -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \ 79 -ldflags "$(shell tools/build_version_flags.sh)" \ 80 -o ${VTROOTBIN} ./go/... 81 82 # build the vitess binaries statically 83 build: 84 ifndef NOBANNER 85 echo $$(date): Building source tree 86 endif 87 bash ./build.env 88 # build all the binaries by default with CGO disabled. 89 # Binaries will be placed in ${VTROOTBIN}. 90 CGO_ENABLED=0 go build \ 91 -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \ 92 -ldflags "$(shell tools/build_version_flags.sh)" \ 93 -o ${VTROOTBIN} ./go/... 94 95 # cross-build can be used to cross-compile Vitess client binaries 96 # Outside of select client binaries (namely vtctlclient & vtexplain), cross-compiled Vitess Binaries are not recommended for production deployments 97 # Usage: GOOS=darwin GOARCH=amd64 make cross-build 98 cross-build: 99 ifndef NOBANNER 100 echo $$(date): Building source tree 101 endif 102 bash ./build.env 103 104 # For the specified GOOS + GOARCH, build all the binaries by default 105 # with CGO disabled. Binaries will be placed in 106 # ${VTROOTBIN}/${GOOS}_${GOARG}. 107 mkdir -p ${VTROOTBIN}/${GOOS}_${GOARCH} 108 CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build \ 109 -trimpath $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \ 110 -ldflags "$(shell tools/build_version_flags.sh)" \ 111 -o ${VTROOTBIN}/${GOOS}_${GOARCH} ./go/... 112 113 @if [ ! -x "${VTROOTBIN}/${GOOS}_${GOARCH}/vttablet" ]; then \ 114 echo "Missing vttablet at: ${VTROOTBIN}/${GOOS}_${GOARCH}." && exit; \ 115 fi 116 117 debug: 118 ifndef NOBANNER 119 echo $$(date): Building source tree 120 endif 121 bash ./build.env 122 go build -trimpath \ 123 $(EXTRA_BUILD_FLAGS) $(VT_GO_PARALLEL) \ 124 -ldflags "$(shell tools/build_version_flags.sh)" \ 125 -gcflags -'N -l' \ 126 -o ${VTROOTBIN} ./go/... 127 128 # install copies the files needed to run Vitess into the given directory tree. 129 # This target is optimized for docker images. It only installs the files needed for running vitess in docker 130 # Usage: make install PREFIX=/path/to/install/root 131 install: build 132 # binaries 133 mkdir -p "$${PREFIX}/bin" 134 cp "$${VTROOTBIN}/"{mysqlctl,mysqlctld,vtorc,vtadmin,vtctld,vtctlclient,vtctldclient,vtgate,vttablet,vtbackup} "$${PREFIX}/bin/" 135 136 # Will only work inside the docker bootstrap for now 137 cross-install: cross-build 138 # binaries 139 mkdir -p "$${PREFIX}/bin" 140 cp "${VTROOTBIN}/${GOOS}_${GOARCH}/"{mysqlctl,mysqlctld,vtorc,vtadmin,vtctld,vtctlclient,vtctldclient,vtgate,vttablet,vtbackup} "$${PREFIX}/bin/" 141 142 # Install local install the binaries needed to run vitess locally 143 # Usage: make install-local PREFIX=/path/to/install/root 144 install-local: build 145 # binaries 146 mkdir -p "$${PREFIX}/bin" 147 cp "$${VTROOT}/bin/"{mysqlctl,mysqlctld,vtorc,vtadmin,vtctl,vtctld,vtctlclient,vtctldclient,vtgate,vttablet,vtbackup} "$${PREFIX}/bin/" 148 149 150 # install copies the files needed to run test Vitess using vtcombo into the given directory tree. 151 # Usage: make install-testing PREFIX=/path/to/install/root 152 install-testing: build 153 # binaries 154 mkdir -p "$${PREFIX}/bin" 155 cp "$${VTROOT}/bin/"{mysqlctld,mysqlctl,vtcombo,vttestserver} "$${PREFIX}/bin/" 156 # config files 157 cp -R config "$${PREFIX}/" 158 159 vtctldclient: go/vt/proto/vtctlservice/vtctlservice.pb.go 160 make -C go/vt/vtctl/vtctldclient 161 162 parser: 163 make -C go/vt/sqlparser 164 165 demo: 166 go install ./examples/demo/demo.go 167 168 codegen: asthelpergen sizegen parser 169 170 visitor: asthelpergen 171 echo "make visitor has been replaced by make asthelpergen" 172 173 asthelpergen: 174 go generate ./go/vt/sqlparser/... 175 176 sizegen: 177 go run ./go/tools/sizegen/sizegen.go \ 178 --in ./go/... \ 179 --gen vitess.io/vitess/go/pools.Setting \ 180 --gen vitess.io/vitess/go/vt/schema.DDLStrategySetting \ 181 --gen vitess.io/vitess/go/vt/vtgate/engine.Plan \ 182 --gen vitess.io/vitess/go/vt/vttablet/tabletserver.TabletPlan \ 183 --gen vitess.io/vitess/go/sqltypes.Result 184 185 # To pass extra flags, run test.go manually. 186 # For example: go run test.go -docker=false -- --extra-flag 187 # For more info see: go run test.go -help 188 test: 189 go run test.go -docker=false 190 191 site_test: unit_test site_integration_test 192 193 clean: 194 go clean -i ./go/... 195 rm -rf third_party/acolyte 196 rm -rf go/vt/.proto.tmp 197 198 # Remove everything including stuff pulled down by bootstrap.sh 199 cleanall: clean 200 # directories created by bootstrap.sh 201 # - exclude vtdataroot and vthook as they may have data we want 202 rm -rf bin dist lib pkg 203 # Remind people to run bootstrap.sh again 204 echo "Please run 'make tools' again to setup your environment" 205 206 unit_test: build dependency_check demo 207 echo $$(date): Running unit tests 208 tools/unit_test_runner.sh 209 210 e2e_test: build 211 echo $$(date): Running endtoend tests 212 go test $(VT_GO_PARALLEL) ./go/.../endtoend/... 213 214 # Run the code coverage tools, compute aggregate. 215 # If you want to improve in a directory, run: 216 # go test -coverprofile=coverage.out && go tool cover -html=coverage.out 217 unit_test_cover: build 218 go test $(VT_GO_PARALLEL) -cover ./go/... | misc/parse_cover.py 219 220 unit_test_race: build dependency_check 221 tools/unit_test_race.sh 222 223 e2e_test_race: build 224 tools/e2e_test_race.sh 225 226 e2e_test_cluster: build 227 tools/e2e_test_cluster.sh 228 229 .ONESHELL: 230 SHELL = /bin/bash 231 .SHELLFLAGS = -ec 232 233 # Run the following tests after making worker changes. 234 worker_test: 235 go test ./go/vt/worker/ 236 go run test.go -docker=false -tag=worker_test 237 238 site_integration_test: 239 go run test.go -docker=false -tag=site_test 240 241 java_test: 242 go install ./go/cmd/vtgateclienttest ./go/cmd/vtcombo 243 VTROOT=${PWD} mvn -f java/pom.xml -B clean verify 244 245 install_protoc-gen-go: 246 GOBIN=$(VTROOTBIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@$(shell go list -m -f '{{ .Version }}' google.golang.org/protobuf) 247 GOBIN=$(VTROOTBIN) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0 # the GRPC compiler its own pinned version 248 GOBIN=$(VTROOTBIN) go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@$(shell go list -m -f '{{ .Version }}' github.com/planetscale/vtprotobuf) 249 250 PROTO_SRCS = $(wildcard proto/*.proto) 251 PROTO_SRC_NAMES = $(basename $(notdir $(PROTO_SRCS))) 252 PROTO_GO_OUTS = $(foreach name, $(PROTO_SRC_NAMES), go/vt/proto/$(name)/$(name).pb.go) 253 # This rule rebuilds all the go files from the proto definitions for gRPC. 254 proto: $(PROTO_GO_OUTS) 255 256 ifndef NOBANNER 257 echo $$(date): Compiling proto definitions 258 endif 259 260 $(PROTO_GO_OUTS): minimaltools install_protoc-gen-go proto/*.proto 261 $(VTROOT)/bin/protoc \ 262 --go_out=. --plugin protoc-gen-go="${VTROOTBIN}/protoc-gen-go" \ 263 --go-grpc_out=. --plugin protoc-gen-go-grpc="${VTROOTBIN}/protoc-gen-go-grpc" \ 264 --go-vtproto_out=. --plugin protoc-gen-go-vtproto="${VTROOTBIN}/protoc-gen-go-vtproto" \ 265 --go-vtproto_opt=features=marshal+unmarshal+size+pool \ 266 --go-vtproto_opt=pool=vitess.io/vitess/go/vt/proto/query.Row \ 267 --go-vtproto_opt=pool=vitess.io/vitess/go/vt/proto/binlogdata.VStreamRowsResponse \ 268 -I${PWD}/dist/vt-protoc-21.3/include:proto $(PROTO_SRCS) 269 cp -Rf vitess.io/vitess/go/vt/proto/* go/vt/proto 270 rm -rf vitess.io/vitess/go/vt/proto/ 271 272 # Helper targets for building Docker images. 273 # Please read docker/README.md to understand the different available images. 274 275 # This rule builds the bootstrap images for all flavors. 276 DOCKER_IMAGES_FOR_TEST = mysql57 mysql80 percona57 percona80 277 DOCKER_IMAGES = common $(DOCKER_IMAGES_FOR_TEST) 278 BOOTSTRAP_VERSION=14.3 279 ensure_bootstrap_version: 280 find docker/ -type f -exec sed -i "s/^\(ARG bootstrap_version\)=.*/\1=${BOOTSTRAP_VERSION}/" {} \; 281 sed -i 's/\(^.*flag.String(\"bootstrap-version\",\) *\"[^\"]\+\"/\1 \"${BOOTSTRAP_VERSION}\"/' test.go 282 283 docker_bootstrap: 284 for i in $(DOCKER_IMAGES); do echo "building bootstrap image: $$i"; docker/bootstrap/build.sh $$i ${BOOTSTRAP_VERSION} || exit 1; done 285 286 docker_bootstrap_test: 287 flavors='$(DOCKER_IMAGES_FOR_TEST)' && ./test.go -pull=false -parallel=2 -bootstrap-version=${BOOTSTRAP_VERSION} -flavor=$${flavors// /,} 288 289 docker_bootstrap_push: 290 for i in $(DOCKER_IMAGES); do echo "pushing bootstrap image: ${BOOTSTRAP_VERSION}-$$i"; docker push vitess/bootstrap:${BOOTSTRAP_VERSION}-$$i || exit 1; done 291 292 # Use this target to update the local copy of your images with the one on Dockerhub. 293 docker_bootstrap_pull: 294 for i in $(DOCKER_IMAGES); do echo "pulling bootstrap image: $$i"; docker pull vitess/bootstrap:${BOOTSTRAP_VERSION}-$$i || exit 1; done 295 296 297 define build_docker_image 298 ${info Building ${2}} 299 # Fix permissions before copying files, to avoid AUFS bug other must have read/access permissions 300 chmod -R o=rx *; 301 302 if grep -q arm64 <<< ${2}; then \ 303 echo "Building docker using arm64 buildx"; \ 304 docker buildx build --platform linux/arm64 -f ${1} -t ${2} --build-arg bootstrap_version=${BOOTSTRAP_VERSION} .; \ 305 else \ 306 echo "Building docker using straight docker build"; \ 307 docker build -f ${1} -t ${2} --build-arg bootstrap_version=${BOOTSTRAP_VERSION} .; \ 308 fi 309 endef 310 311 docker_base: 312 ${call build_docker_image,docker/base/Dockerfile,vitess/base} 313 314 DOCKER_BASE_SUFFIX = mysql80 percona57 percona80 315 DOCKER_BASE_TARGETS = $(addprefix docker_base_, $(DOCKER_BASE_SUFFIX)) 316 $(DOCKER_BASE_TARGETS): docker_base_%: 317 ${call build_docker_image,docker/base/Dockerfile.$*,vitess/base:$*} 318 319 docker_base_all: docker_base $(DOCKER_BASE_TARGETS) 320 321 docker_lite: 322 ${call build_docker_image,docker/lite/Dockerfile,vitess/lite} 323 324 DOCKER_LITE_SUFFIX = mysql57 ubi7.mysql57 mysql80 ubi7.mysql80 percona57 ubi7.percona57 percona80 ubi7.percona80 testing ubi8.mysql80 ubi8.arm64.mysql80 325 DOCKER_LITE_TARGETS = $(addprefix docker_lite_,$(DOCKER_LITE_SUFFIX)) 326 $(DOCKER_LITE_TARGETS): docker_lite_%: 327 ${call build_docker_image,docker/lite/Dockerfile.$*,vitess/lite:$*} 328 329 docker_lite_all: docker_lite $(DOCKER_LITE_TARGETS) 330 331 docker_local: 332 ${call build_docker_image,docker/local/Dockerfile,vitess/local} 333 334 docker_run_local: 335 ./docker/local/run.sh 336 337 docker_mini: 338 ${call build_docker_image,docker/mini/Dockerfile,vitess/mini} 339 340 DOCKER_VTTESTSERVER_SUFFIX = mysql57 mysql80 341 DOCKER_VTTESTSERVER_TARGETS = $(addprefix docker_vttestserver_,$(DOCKER_VTTESTSERVER_SUFFIX)) 342 $(DOCKER_VTTESTSERVER_TARGETS): docker_vttestserver_%: 343 ${call build_docker_image,docker/vttestserver/Dockerfile.$*,vitess/vttestserver:$*} 344 345 docker_vttestserver: $(DOCKER_VTTESTSERVER_TARGETS) 346 # This rule loads the working copy of the code into a bootstrap image, 347 # and then runs the tests inside Docker. 348 # Example: $ make docker_test flavor=mysql80 349 docker_test: 350 go run test.go -flavor $(flavor) 351 352 docker_unit_test: 353 go run test.go -flavor $(flavor) unit 354 355 # Release a version. 356 # This will generate a tar.gz file into the releases folder with the current source 357 release: docker_base 358 @if [ -z "$VERSION" ]; then \ 359 echo "Set the env var VERSION with the release version"; exit 1;\ 360 fi 361 mkdir -p releases 362 docker build -f docker/Dockerfile.release -t vitess/release . 363 docker run -v ${PWD}/releases:/vt/releases --env VERSION=$(VERSION) vitess/release 364 git tag -m Version\ $(VERSION) v$(VERSION) 365 echo "A git tag was created, you can push it with:" 366 echo "git push origin v$(VERSION)" 367 echo "Also, don't forget the upload releases/v$(VERSION).tar.gz file to GitHub releases" 368 369 create_release: 370 ./tools/create_release.sh 371 372 back_to_dev_mode: 373 ./tools/back_to_dev_mode.sh 374 375 tools: 376 echo $$(date): Installing dependencies 377 ./bootstrap.sh 378 379 minimaltools: 380 echo $$(date): Installing minimal dependencies 381 BUILD_CHROME=0 BUILD_JAVA=0 BUILD_CONSUL=0 ./bootstrap.sh 382 383 dependency_check: 384 ./tools/dependency_check.sh 385 386 install_k8s-code-generator: tools/tools.go go.mod 387 go install k8s.io/code-generator/cmd/deepcopy-gen 388 go install k8s.io/code-generator/cmd/client-gen 389 go install k8s.io/code-generator/cmd/lister-gen 390 go install k8s.io/code-generator/cmd/informer-gen 391 392 DEEPCOPY_GEN=$(VTROOTBIN)/deepcopy-gen 393 CLIENT_GEN=$(VTROOTBIN)/client-gen 394 LISTER_GEN=$(VTROOTBIN)/lister-gen 395 INFORMER_GEN=$(VTROOTBIN)/informer-gen 396 397 GEN_BASE_DIR ?= vitess.io/vitess/go/vt/topo/k8stopo 398 399 client_go_gen: install_k8s-code-generator 400 echo $$(date): Regenerating client-go code 401 # Delete and re-generate the deepcopy types 402 find $(VTROOT)/go/vt/topo/k8stopo/apis/topo/v1beta1 -name "zz_generated.deepcopy.go" -delete 403 404 # We output to ./ and then copy over the generated files to the appropriate path 405 # This is done so we don't have rely on the repository being cloned to `$GOPATH/src/vitess.io/vitess` 406 407 $(DEEPCOPY_GEN) -o ./ \ 408 --input-dirs $(GEN_BASE_DIR)/apis/topo/v1beta1 \ 409 -O zz_generated.deepcopy \ 410 --bounding-dirs $(GEN_BASE_DIR)/apis \ 411 --go-header-file ./go/vt/topo/k8stopo/boilerplate.go.txt 412 413 # Delete existing code 414 rm -rf go/vt/topo/k8stopo/client 415 416 # Generate clientset 417 $(CLIENT_GEN) -o ./ \ 418 --clientset-name versioned \ 419 --input-base $(GEN_BASE_DIR)/apis \ 420 --input 'topo/v1beta1' \ 421 --output-package $(GEN_BASE_DIR)/client/clientset \ 422 --fake-clientset=true \ 423 --go-header-file ./go/vt/topo/k8stopo/boilerplate.go.txt 424 425 # Generate listers 426 $(LISTER_GEN) -o ./ \ 427 --input-dirs $(GEN_BASE_DIR)/apis/topo/v1beta1 \ 428 --output-package $(GEN_BASE_DIR)/client/listers \ 429 --go-header-file ./go/vt/topo/k8stopo/boilerplate.go.txt 430 431 # Generate informers 432 $(INFORMER_GEN) -o ./ \ 433 --input-dirs $(GEN_BASE_DIR)/apis/topo/v1beta1 \ 434 --output-package $(GEN_BASE_DIR)/client/informers \ 435 --versioned-clientset-package $(GEN_BASE_DIR)/client/clientset/versioned \ 436 --listers-package $(GEN_BASE_DIR)/client/listers \ 437 --go-header-file ./go/vt/topo/k8stopo/boilerplate.go.txt 438 439 # Move and cleanup 440 mv vitess.io/vitess/go/vt/topo/k8stopo/client go/vt/topo/k8stopo/ 441 mv vitess.io/vitess/go/vt/topo/k8stopo/apis/topo/v1beta1/zz_generated.deepcopy.go go/vt/topo/k8stopo/apis/topo/v1beta1/zz_generated.deepcopy.go 442 rm -rf vitess.io/vitess/go/vt/topo/k8stopo/ 443 444 vtadmin_web_install: 445 cd web/vtadmin && npm install 446 447 # Generate JavaScript/TypeScript bindings for vtadmin-web from the Vitess .proto files. 448 # Eventually, we'll want to call this target as part of the standard `make proto` target. 449 # While vtadmin-web is new and unstable, however, we can keep it out of the critical build path. 450 vtadmin_web_proto_types: vtadmin_web_install 451 ./web/vtadmin/bin/generate-proto-types.sh 452 453 vtadmin_authz_testgen: 454 go generate ./go/vt/vtadmin/ 455 go fmt ./go/vt/vtadmin/ 456 457 # Generate github CI actions workflow files for unit tests and cluster endtoend tests based on templates in the test/templates directory 458 # Needs to be called if the templates change or if a new test "shard" is created. We do not need to rebuild tests if only the test/config.json 459 # is changed by adding a new test to an existing shard. Any new or modified files need to be committed into git 460 generate_ci_workflows: 461 cd test && go run ci_workflow_gen.go && cd .. 462 463 release-notes: 464 go run ./go/tools/release-notes --from "$(FROM)" --to "$(TO)" --version "$(VERSION)" --summary "$(SUMMARY)" 465 466 install_kubectl_kind: 467 ./tools/get_kubectl_kind.sh