forked from apache/cloudberry-gpbackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (114 loc) · 5.17 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
all: build
ifndef GOPATH
$(error Environment variable GOPATH is not set)
endif
.DEFAULT_GOAL := all
BACKUP=gpbackup
RESTORE=gprestore
HELPER=gpbackup_helper
VERSION="1.2.7-beta1+dev.7"
BIN_DIR=$(shell echo $${GOPATH:-~/go} | awk -F':' '{ print $$1 "/bin"}')
GINKGO_FLAGS := -r
GIT_VERSION := $(shell git describe --tags | perl -pe 's/(.*)-([0-9]*)-(g[0-9a-f]*)/\1+dev.\2.\3/')
BACKUP_VERSION_STR=github.com/cloudberrydb/gpbackup/backup.version=$(VERSION)
RESTORE_VERSION_STR=github.com/cloudberrydb/gpbackup/restore.version=$(VERSION)
HELPER_VERSION_STR=github.com/cloudberrydb/gpbackup/helper.version=$(VERSION)
# note that /testutils is not a production directory, but has unit tests to validate testing tools
SUBDIRS_HAS_UNIT=backup/ filepath/ history/ helper/ options/ report/ restore/ toc/ utils/ testutils/
SUBDIRS_ALL=$(SUBDIRS_HAS_UNIT) integration/ end_to_end/
GOLANG_LINTER=$(GOPATH)/bin/golangci-lint
GINKGO=$(GOPATH)/bin/ginkgo
GOIMPORTS=$(GOPATH)/bin/goimports
GO_BUILD=go build -mod=readonly
DEBUG=-gcflags=all="-N -l"
CUSTOM_BACKUP_DIR ?= "/tmp"
helper_path ?= $(BIN_DIR)/$(HELPER)
depend :
go mod download
$(GINKGO) : # v1.14.0 is compatible with centos6 default gcc version
go install github.com/onsi/ginkgo/v2/[email protected]
$(GOIMPORTS) :
go install golang.org/x/tools/cmd/goimports@latest
format : $(GOIMPORTS)
@goimports -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")
LINTER_VERSION=1.16.0
$(GOLANG_LINTER) :
mkdir -p $(GOPATH)/bin
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v${LINTER_VERSION}
.PHONY : coverage integration end_to_end
lint : $(GOLANG_LINTER)
golangci-lint run --tests=false
unit : $(GINKGO)
ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
unit_all_gpdb_versions : $(GINKGO)
TEST_GPDB_VERSION=4.3.999 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
TEST_GPDB_VERSION=5.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
TEST_GPDB_VERSION=6.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
TEST_GPDB_VERSION=7.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1 # GPDB main
integration : $(GINKGO)
ginkgo $(GINKGO_FLAGS) integration 2>&1
test : build unit
end_to_end : $(GINKGO)
ginkgo $(GINKGO_FLAGS) --timeout=3h end_to_end -- --custom_backup_dir $(CUSTOM_BACKUP_DIR) 2>&1
coverage :
@./show_coverage.sh
build :
$(GO_BUILD) -tags '$(BACKUP)' -o $(BIN_DIR)/$(BACKUP) -ldflags "-X $(BACKUP_VERSION_STR)"
$(GO_BUILD) -tags '$(RESTORE)' -o $(BIN_DIR)/$(RESTORE) -ldflags "-X $(RESTORE_VERSION_STR)"
$(GO_BUILD) -tags '$(HELPER)' -o $(BIN_DIR)/$(HELPER) -ldflags "-X $(HELPER_VERSION_STR)"
debug :
$(GO_BUILD) -tags '$(BACKUP)' -o $(BIN_DIR)/$(BACKUP) -ldflags "-X $(BACKUP_VERSION_STR)" $(DEBUG)
$(GO_BUILD) -tags '$(RESTORE)' -o $(BIN_DIR)/$(RESTORE) -ldflags "-X $(RESTORE_VERSION_STR)" $(DEBUG)
$(GO_BUILD) -tags '$(HELPER)' -o $(BIN_DIR)/$(HELPER) -ldflags "-X $(HELPER_VERSION_STR)" $(DEBUG)
build_linux :
env GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags '$(BACKUP)' -o $(BACKUP) -ldflags "-X $(BACKUP_VERSION_STR)"
env GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags '$(RESTORE)' -o $(RESTORE) -ldflags "-X $(RESTORE_VERSION_STR)"
env GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags '$(HELPER)' -o $(HELPER) -ldflags "-X $(HELPER_VERSION_STR)"
install :
cp $(BIN_DIR)/$(BACKUP) $(BIN_DIR)/$(RESTORE) $(GPHOME)/bin
@psql -X -t -d template1 -c 'select distinct hostname from gp_segment_configuration where content != -1' > /tmp/seg_hosts 2>/dev/null; \
if [ $$? -eq 0 ]; then \
gpscp -f /tmp/seg_hosts $(helper_path) =:$(GPHOME)/bin/$(HELPER); \
if [ $$? -eq 0 ]; then \
echo 'Successfully copied gpbackup_helper to $(GPHOME) on all segments'; \
else \
echo 'Failed to copy gpbackup_helper to $(GPHOME)'; \
exit 1; \
fi; \
else \
echo 'Database is not running, please start the database and run this make target again'; \
exit 1; \
fi; \
rm /tmp/seg_hosts
clean :
# Build artifacts
rm -f $(BIN_DIR)/$(BACKUP) $(BACKUP) $(BIN_DIR)/$(RESTORE) $(RESTORE) $(BIN_DIR)/$(HELPER) $(HELPER)
# Test artifacts
rm -rf /tmp/go-build* /tmp/gexec_artifacts* /tmp/ginkgo*
docker stop s3-minio # stop minio before removing its data directories
docker rm s3-minio
rm -rf /tmp/minio
rm -f /tmp/minio_config.yaml
# Code coverage files
rm -rf /tmp/cover* /tmp/unit*
go clean -i -r -x -testcache -modcache
error-report:
@echo "Error messaging:"
@echo ""
@ag "gplog.Error|gplog.Fatal|ors.New|errors.Error|CheckClusterError|GpexpandFailureMessage =|errMsg :=" --ignore "*_test*" | grep -v "FatalOnError(err)" | grep -v ".Error()"
warning-report:
@echo "Warning messaging:"
@echo ""
@ag "gplog.Warn" --ignore "*_test*"
info-report:
@echo "Info and verbose messaging:"
@echo ""
@ag "gplog.Info|gplog.Verbose" --ignore "*_test*"
test-s3-local: build install
${PWD}/plugins/generate_minio_config.sh
mkdir -p /tmp/minio/gpbackup-s3-test
docker run -d --name s3-minio -p 9000:9000 -p 9001:9001 -v /tmp/minio:/data/minio quay.io/minio/minio server /data/minio --console-address ":9001"
sleep 2 # Wait for minio server to start up
${PWD}/plugins/plugin_test.sh $(BIN_DIR)/gpbackup_s3_plugin /tmp/minio_config.yaml
docker stop s3-minio
docker rm s3-minio