wal-g
/
Makefile
310 строк · 12.1 Кб
1MAIN_PG_PATH := main/pg2MAIN_MYSQL_PATH := main/mysql3MAIN_SQLSERVER_PATH := main/sqlserver4MAIN_REDIS_PATH := main/redis5MAIN_MONGO_PATH := main/mongo6MAIN_FDB_PATH := main/fdb7MAIN_GP_PATH := main/gp8MAIN_ETCD_PATH := main/etcd9DOCKER_COMMON := golang ubuntu ubuntu_20_04 s310CMD_FILES = $(wildcard cmd/**/*.go)11PKG_FILES = $(wildcard internal/**/*.go internal/**/**/*.go internal/*.go)12TEST_FILES = $(wildcard test/*.go testtools/*.go)13PKG := github.com/wal-g/wal-g14COVERAGE_FILE := coverage.out15TEST := "pg_tests"16MYSQL_TEST := "mysql_base_tests"17MONGO_MAJOR ?= "4.2"18MONGO_VERSION ?= "4.2.8"19GOLANGCI_LINT_VERSION ?= "v1.52.2"20REDIS_VERSION ?= "5.0.8"21TOOLS_MOD_DIR := ./internal/tools22
23BUILD_TAGS:=24
25ifdef USE_BROTLI26BUILD_TAGS:=$(BUILD_TAGS) brotli27endif
28
29ifdef USE_LIBSODIUM30BUILD_TAGS:=$(BUILD_TAGS) libsodium31endif
32
33ifdef USE_LZO34BUILD_TAGS:=$(BUILD_TAGS) lzo35endif
36
37.PHONY: unittest fmt lint clean install_tools38
39test: deps unittest pg_build mysql_build redis_build mongo_build gp_build unlink_brotli pg_integration_test mysql_integration_test redis_integration_test fdb_integration_test gp_integration_test etcd_integration_test40
41pg_test: deps pg_build unlink_brotli pg_integration_test42
43pg_build: $(CMD_FILES) $(PKG_FILES)44(cd $(MAIN_PG_PATH) && go build -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w -X github.com/wal-g/wal-g/cmd/pg.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X github.com/wal-g/wal-g/cmd/pg.gitRevision=`git rev-parse --short HEAD` -X github.com/wal-g/wal-g/cmd/pg.walgVersion=`git tag -l --points-at HEAD`")45
46install_and_build_pg: deps pg_build47
48pg_build_image:49# There are dependencies between container images.50# Running in one command leads to using outdated images and fails on clean system.51# It can not be fixed with depends_on in compose file. https://github.com/docker/compose/issues/633252docker-compose build $(DOCKER_COMMON)53docker-compose build pg
54docker-compose build pg_build_docker_prefix
55
56pg_save_image: install_and_build_pg pg_build_image57mkdir -p ${CACHE_FOLDER}58sudo rm -rf ${CACHE_FOLDER}/*59docker save ${IMAGE} | gzip -c > ${CACHE_FILE_DOCKER_PREFIX}60docker save ${IMAGE_UBUNTU_18_04} | gzip -c > ${CACHE_FILE_UBUNTU_18_04}61docker save ${IMAGE_UBUNTU_20_04} | gzip -c > ${CACHE_FILE_UBUNTU_20_04}62docker save ${IMAGE_GOLANG} | gzip -c > ${CACHE_FILE_GOLANG}63ls ${CACHE_FOLDER}64
65pg_integration_test: clean_compose66@if [ "x" = "${CACHE_FILE_DOCKER_PREFIX}x" ]; then\67echo "Rebuild";\68make install_and_build_pg;\69make pg_build_image;\70else\71docker load -i ${CACHE_FILE_DOCKER_PREFIX};\72fi
73@if echo "$(TEST)" | grep -Fqe "pgbackrest"; then\74docker-compose build pg_pgbackrest;\75fi
76@if echo "$(TEST)" | grep -Fqe "pg_ssh_"; then\77docker-compose build ssh;\78fi
79
80docker-compose up --exit-code-from $(TEST) $(TEST)81# Run tests with dependencies if we run all tests82@if [ "$(TEST)" = "pg_tests" ]; then\83docker-compose build pg_pgbackrest ssh swift pg_wal_perftest_with_throttling &&\
84docker-compose up --exit-code-from pg_ssh_backup_test pg_ssh_backup_test &&\
85docker-compose up --exit-code-from pg_storage_swift_test pg_storage_swift_test &&\
86docker-compose up --exit-code-from pg_storage_ssh_test pg_storage_ssh_test &&\
87docker-compose up --exit-code-from pg_pgbackrest_backup_fetch_test pg_pgbackrest_backup_fetch_test &&\
88docker-compose down &&\
89sleep 5 &&\
90docker-compose up --exit-code-from pg_wal_perftest_with_throttling pg_wal_perftest_with_throttling ;\91fi
92make clean_compose
93
94.PHONY: clean_compose95clean_compose:96services=$$(docker-compose ps -a --format '{{.Name}} {{.Service}}' | grep wal-g_ | cut -w -f 2); \97if [ "$$services" ]; then docker-compose down $$services; fi98
99all_unittests: deps unittest100
101# todo Should we remove this target as a duplicate of pg_integration_test?
102pg_int_tests_only:103docker-compose build pg_tests
104docker-compose up --exit-code-from pg_tests pg_tests
105
106pg_clean:107(cd $(MAIN_PG_PATH) && go clean)108./cleanup.sh
109
110pg_install: pg_build111mv $(MAIN_PG_PATH)/wal-g $(GOBIN)/wal-g112
113mysql_base: deps mysql_build unlink_brotli114mysql_test: deps mysql_build unlink_brotli mysql_integration_test115
116mysql_build: $(CMD_FILES) $(PKG_FILES)117(cd $(MAIN_MYSQL_PATH) && go build -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w -X github.com/wal-g/wal-g/cmd/mysql.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X github.com/wal-g/wal-g/cmd/mysql.gitRevision=`git rev-parse --short HEAD` -X github.com/wal-g/wal-g/cmd/mysql.walgVersion=`git tag -l --points-at HEAD`")118
119sqlserver_build: $(CMD_FILES) $(PKG_FILES)120(cd $(MAIN_SQLSERVER_PATH) && go build -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w -X github.com/wal-g/wal-g/cmd/sqlserver.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X github.com/wal-g/wal-g/cmd/sqlserver.gitRevision=`git rev-parse --short HEAD` -X github.com/wal-g/wal-g/cmd/sqlserver.walgVersion=`git tag -l --points-at HEAD`")121
122load_docker_common:123@if [ "x" = "${CACHE_FOLDER}x" ]; then\124echo "Rebuild";\125docker-compose build $(DOCKER_COMMON);\126else\127docker load -i ${CACHE_FILE_UBUNTU_18_04};\128docker load -i ${CACHE_FILE_UBUNTU_20_04};\129docker load -i ${CACHE_FILE_GOLANG};\130fi
131
132mysql_integration_test: deps mysql_build unlink_brotli load_docker_common133./link_brotli.sh
134docker-compose build mysql $(MYSQL_TEST)135docker-compose up --force-recreate --exit-code-from $(MYSQL_TEST) $(MYSQL_TEST)136
137mysql_clean:138(cd $(MAIN_MYSQL_PATH) && go clean)139./cleanup.sh
140
141mysql_install: mysql_build142mv $(MAIN_MYSQL_PATH)/wal-g $(GOBIN)/wal-g143
144mariadb_test: deps mysql_build unlink_brotli mariadb_integration_test145
146mariadb_integration_test: unlink_brotli load_docker_common147./link_brotli.sh
148docker-compose build mariadb mariadb_tests
149docker-compose up --force-recreate --exit-code-from mariadb_tests mariadb_tests
150
151mongo_test: deps mongo_build unlink_brotli152
153mongo_build: $(CMD_FILES) $(PKG_FILES)154(cd $(MAIN_MONGO_PATH) && go build $(BUILD_ARGS) -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w -X github.com/wal-g/wal-g/cmd/mongo.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X github.com/wal-g/wal-g/cmd/mongo.gitRevision=`git rev-parse --short HEAD` -X github.com/wal-g/wal-g/cmd/mongo.walgVersion=`git tag -l --points-at HEAD`")155
156mongo_install: mongo_build157mv $(MAIN_MONGO_PATH)/wal-g $(GOBIN)/wal-g158
159mongo_features:160set -e
161make go_deps
162cd tests_func/ && MONGO_MAJOR=$(MONGO_MAJOR) MONGO_VERSION=$(MONGO_VERSION) go test -v -count=1 -timeout 20m --tf.test=true --tf.debug=true --tf.clean=true --tf.stop=true --tf.database=mongodb163
164clean_mongo_features:165set -e
166cd tests_func/ && MONGO_MAJOR=$(MONGO_MAJOR) MONGO_VERSION=$(MONGO_VERSION) go test -v -count=1 -timeout 5m --tf.test=false --tf.debug=false --tf.clean=true --tf.stop=true --tf.database=mongodb167
168fdb_build: $(CMD_FILES) $(PKG_FILES)169(cd $(MAIN_FDB_PATH) && go build -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w")170
171fdb_install: fdb_build172mv $(MAIN_FDB_PATH)/wal-g $(GOBIN)/wal-g173
174fdb_integration_test: load_docker_common175docker-compose down -v
176docker-compose build fdb_tests
177docker-compose up --force-recreate --renew-anon-volumes --exit-code-from fdb_tests fdb_tests
178
179redis_test: deps redis_build unlink_brotli redis_integration_test180
181redis_build: $(CMD_FILES) $(PKG_FILES)182(cd $(MAIN_REDIS_PATH) && go build -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w -X github.com/wal-g/wal-g/cmd/redis.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X github.com/wal-g/wal-g/cmd/redis.gitRevision=`git rev-parse --short HEAD` -X github.com/wal-g/wal-g/cmd/redis.walgVersion=`git tag -l --points-at HEAD`")183
184redis_integration_test: load_docker_common185docker-compose build redis redis_tests
186docker-compose up --exit-code-from redis_tests redis_tests
187
188redis_clean:189(cd $(MAIN_REDIS_PATH) && go clean)190./cleanup.sh
191
192redis_install: redis_build193mv $(MAIN_REDIS_PATH)/wal-g $(GOBIN)/wal-g194
195redis_features:196set -e
197make go_deps
198cd tests_func/ && REDIS_VERSION=$(REDIS_VERSION) go test -v -count=1 -timeout 20m --tf.test=true --tf.debug=false --tf.clean=true --tf.stop=true --tf.database=redis199
200clean_redis_features:201set -e
202cd tests_func/ && REDIS_VERSION=$(REDIS_VERSION) go test -v -count=1 -timeout 5m --tf.test=false --tf.debug=false --tf.clean=true --tf.stop=true --tf.database=redis203
204etcd_test: deps etcd_build unlink_brotli etcd_integration_test205
206etcd_build: $(CMD_FILES) $(PKG_FILES)207(cd $(MAIN_ETCD_PATH) && go build -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w -X github.com/wal-g/wal-g/cmd/etcd.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X github.com/wal-g/wal-g/cmd/etcd.gitRevision=`git rev-parse --short HEAD` -X github.com/wal-g/wal-g/cmd/etcd.walgVersion=`git tag -l --points-at HEAD`")208
209etcd_install: etcd_build210mv $(MAIN_ETCD_PATH)/wal-g $(GOBIN)/wal-g211
212etcd_clean:213(cd $(MAIN_ETCD_PATH) && go clean)214./cleanup.sh
215
216# refactor
217etcd_integration_test: load_docker_common218docker-compose build etcd etcd_tests
219docker-compose up --exit-code-from etcd_tests etcd_tests
220
221gp_build: $(CMD_FILES) $(PKG_FILES)222(cd $(MAIN_GP_PATH) && go build -mod vendor -tags "$(BUILD_TAGS)" -o wal-g -ldflags "-s -w -X github.com/wal-g/wal-g/cmd/gp.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X github.com/wal-g/wal-g/cmd/gp.gitRevision=`git rev-parse --short HEAD` -X github.com/wal-g/wal-g/cmd/gp.walgVersion=`git tag -l --points-at HEAD`")223
224gp_clean:225(cd $(MAIN_GP_PATH) && go clean)226./cleanup.sh
227
228gp_install: gp_build229mv $(MAIN_GP_PATH)/wal-g $(GOBIN)/wal-g230
231gp_test: deps gp_build unlink_brotli gp_integration_test232
233gp_integration_test: load_docker_common234docker-compose build gp gp_tests
235docker-compose up --exit-code-from gp_tests gp_tests
236
237st_test: deps pg_build unlink_brotli st_integration_test238
239st_integration_test: load_docker_common240docker-compose build st_tests
241docker-compose up --exit-code-from st_tests st_tests
242
243unittest:244go list ./... | grep -Ev 'vendor|submodules|tmp' | xargs go vet245go test -mod vendor -v $(TEST_MODIFIER) -tags "$(BUILD_TAGS)" ./internal/...246go test -mod vendor -v $(TEST_MODIFIER) -tags "$(BUILD_TAGS)" ./pkg/...247go test -mod vendor -v $(TEST_MODIFIER) -tags "$(BUILD_TAGS)" ./utility/...248
249coverage:250go list ./... | grep -Ev 'vendor|submodules|tmp' | xargs go test -v $(TEST_MODIFIER) -coverprofile=$(COVERAGE_FILE) | grep -v 'no test files'251go tool cover -html=$(COVERAGE_FILE)252
253install_tools:254cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/cmd/goimports255$(warning Please run make docker_lint for lint. It is unreliable to use self-compiled golangci-lint. \256https://golangci-lint.run/usage/install/#install-from-source)257cd $(TOOLS_MOD_DIR) && go install github.com/golangci/golangci-lint/cmd/golangci-lint258
259fmt: $(CMD_FILES) $(PKG_FILES) $(TEST_FILES)260gofmt -s -w $(CMD_FILES) $(PKG_FILES) $(TEST_FILES)261
262goimports: install_tools $(CMD_FILES) $(PKG_FILES) $(TEST_FILES)263goimports -w $(CMD_FILES) $(PKG_FILES) $(TEST_FILES)264
265lint: install_tools266golangci-lint run --allow-parallel-runners ./...
267
268docker_lint:269docker build -t wal-g/lint --build-arg TAG=$(GOLANGCI_LINT_VERSION) - < docker/lint/Dockerfile270docker run --rm -v `pwd`:/app \271-v wal-g_lint_cache:/cache -e GOLANGCI_LINT_CACHE=/cache/lint \272-e GOCACHE=/cache/go -e GOMODCACHE=/cache/gomod \273wal-g/lint golangci-lint run -v
274
275deps: go_deps link_external_deps276
277go_deps:278git submodule update --init
279go mod vendor
280ifdef USE_LZO281sed -i 's|\(#cgo LDFLAGS:\) .*|\1 -Wl,-Bstatic -llzo2 -Wl,-Bdynamic|' vendor/github.com/cyberdelia/lzo/lzo.go282endif
283
284link_external_deps: link_brotli link_libsodium285
286unlink_external_deps: unlink_brotli unlink_libsodium287
288install:289@echo "Nothing to be done. Use pg_install/mysql_install/mongo_install/fdb_install/gp_install/etcd_install... instead."290
291link_brotli:292@if [ -n "${USE_BROTLI}" ]; then ./link_brotli.sh; fi293@if [ -z "${USE_BROTLI}" ]; then echo "info: USE_BROTLI is not set, skipping 'link_brotli' task"; fi294
295link_libsodium:296@if [ ! -z "${USE_LIBSODIUM}" ]; then\297./link_libsodium.sh;\298fi
299
300unlink_brotli:301rm -rf vendor/github.com/google/brotli/*
302if [ -n "${USE_BROTLI}" ] ; then mv tmp/brotli/* vendor/github.com/google/brotli/; fi303rm -rf tmp/brotli
304
305unlink_libsodium:306rm -rf tmp/libsodium
307
308build_client:309cd cmd/daemonclient && \
310go build -o ../../bin/walg-daemon-client -ldflags "-s -w -X main.buildDate=`date -u +%Y.%m.%d_%H:%M:%S` -X main.gitRevision=`git rev-parse --short HEAD` -X main.version=`git tag -l --points-at HEAD`"311