github.com/tuhaihe/gpbackup@v1.0.3/Makefile (about)

     1  all: build
     2  
     3  ifndef GOPATH
     4  $(error Environment variable GOPATH is not set)
     5  endif
     6  
     7  .DEFAULT_GOAL := all
     8  BACKUP=gpbackup
     9  RESTORE=gprestore
    10  HELPER=gpbackup_helper
    11  VERSION="1.2.7-beta1+dev.7"
    12  BIN_DIR=$(shell echo $${GOPATH:-~/go} | awk -F':' '{ print $$1 "/bin"}')
    13  GINKGO_FLAGS := -r 
    14  GIT_VERSION := $(shell git describe --tags | perl -pe 's/(.*)-([0-9]*)-(g[0-9a-f]*)/\1+dev.\2.\3/')
    15  BACKUP_VERSION_STR=github.com/tuhaihe/gpbackup/backup.version=$(VERSION)
    16  RESTORE_VERSION_STR=github.com/tuhaihe/gpbackup/restore.version=$(VERSION)
    17  HELPER_VERSION_STR=github.com/tuhaihe/gpbackup/helper.version=$(VERSION)
    18  
    19  # note that /testutils is not a production directory, but has unit tests to validate testing tools
    20  SUBDIRS_HAS_UNIT=backup/ filepath/ history/ helper/ options/ report/ restore/ toc/ utils/ testutils/
    21  SUBDIRS_ALL=$(SUBDIRS_HAS_UNIT) integration/ end_to_end/
    22  GOLANG_LINTER=$(GOPATH)/bin/golangci-lint
    23  GINKGO=$(GOPATH)/bin/ginkgo
    24  GOIMPORTS=$(GOPATH)/bin/goimports
    25  GO_BUILD=go build -mod=readonly
    26  DEBUG=-gcflags=all="-N -l"
    27  
    28  CUSTOM_BACKUP_DIR ?= "/tmp"
    29  helper_path ?= $(BIN_DIR)/$(HELPER)
    30  
    31  depend :
    32  	go mod download
    33  
    34  $(GINKGO) : # v1.14.0 is compatible with centos6 default gcc version
    35  	go install github.com/onsi/ginkgo/v2/ginkgo@v2.2.0
    36  
    37  $(GOIMPORTS) :
    38  	go install golang.org/x/tools/cmd/goimports@latest
    39  
    40  format : $(GOIMPORTS)
    41  		@goimports -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")
    42  
    43  LINTER_VERSION=1.16.0
    44  $(GOLANG_LINTER) :
    45  		mkdir -p $(GOPATH)/bin
    46  		curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v${LINTER_VERSION}
    47  
    48  .PHONY : coverage integration end_to_end
    49  
    50  lint : $(GOLANG_LINTER)
    51  		golangci-lint run --tests=false
    52  
    53  unit : $(GINKGO)
    54  	ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
    55  
    56  unit_all_gpdb_versions : $(GINKGO)
    57  		TEST_GPDB_VERSION=4.3.999 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
    58  		TEST_GPDB_VERSION=5.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
    59  		TEST_GPDB_VERSION=6.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1
    60  		TEST_GPDB_VERSION=7.999.0 ginkgo $(GINKGO_FLAGS) $(SUBDIRS_HAS_UNIT) 2>&1 # GPDB main
    61  
    62  integration : $(GINKGO)
    63  	ginkgo $(GINKGO_FLAGS) integration 2>&1
    64  
    65  test : build unit 
    66  
    67  end_to_end : $(GINKGO)
    68  	ginkgo $(GINKGO_FLAGS) --timeout=3h  end_to_end -- --custom_backup_dir $(CUSTOM_BACKUP_DIR) 2>&1
    69  
    70  coverage :
    71  		@./show_coverage.sh
    72  
    73  build :
    74  		$(GO_BUILD) -tags '$(BACKUP)' -o $(BIN_DIR)/$(BACKUP) -ldflags "-X $(BACKUP_VERSION_STR)"
    75  		$(GO_BUILD) -tags '$(RESTORE)' -o $(BIN_DIR)/$(RESTORE) -ldflags "-X $(RESTORE_VERSION_STR)"
    76  		$(GO_BUILD) -tags '$(HELPER)' -o $(BIN_DIR)/$(HELPER) -ldflags "-X $(HELPER_VERSION_STR)"
    77  
    78  debug :
    79  		$(GO_BUILD) -tags '$(BACKUP)' -o $(BIN_DIR)/$(BACKUP) -ldflags "-X $(BACKUP_VERSION_STR)" $(DEBUG)
    80  		$(GO_BUILD) -tags '$(RESTORE)' -o $(BIN_DIR)/$(RESTORE) -ldflags "-X $(RESTORE_VERSION_STR)" $(DEBUG)
    81  		$(GO_BUILD) -tags '$(HELPER)' -o $(BIN_DIR)/$(HELPER) -ldflags "-X $(HELPER_VERSION_STR)" $(DEBUG)
    82  
    83  build_linux :
    84  		env GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags '$(BACKUP)' -o $(BACKUP) -ldflags "-X $(BACKUP_VERSION_STR)"
    85  		env GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags '$(RESTORE)' -o $(RESTORE) -ldflags "-X $(RESTORE_VERSION_STR)"
    86  		env GOOS=linux GOARCH=amd64 $(GO_BUILD) -tags '$(HELPER)' -o $(HELPER) -ldflags "-X $(HELPER_VERSION_STR)"
    87  
    88  install :
    89  		cp $(BIN_DIR)/$(BACKUP) $(BIN_DIR)/$(RESTORE) $(GPHOME)/bin
    90  		@psql -X -t -d template1 -c 'select distinct hostname from gp_segment_configuration where content != -1' > /tmp/seg_hosts 2>/dev/null; \
    91  		if [ $$? -eq 0 ]; then \
    92  			gpscp -f /tmp/seg_hosts $(helper_path) =:$(GPHOME)/bin/$(HELPER); \
    93  			if [ $$? -eq 0 ]; then \
    94  				echo 'Successfully copied gpbackup_helper to $(GPHOME) on all segments'; \
    95  			else \
    96  				echo 'Failed to copy gpbackup_helper to $(GPHOME)'; \
    97  				exit 1;	 \
    98  			fi; \
    99  		else \
   100  			echo 'Database is not running, please start the database and run this make target again'; \
   101  				exit 1;	 \
   102  		fi; \
   103  		rm /tmp/seg_hosts
   104  
   105  clean :
   106  		# Build artifacts
   107  		rm -f $(BIN_DIR)/$(BACKUP) $(BACKUP) $(BIN_DIR)/$(RESTORE) $(RESTORE) $(BIN_DIR)/$(HELPER) $(HELPER)
   108  		# Test artifacts
   109  		rm -rf /tmp/go-build* /tmp/gexec_artifacts* /tmp/ginkgo*
   110  		docker stop s3-minio # stop minio before removing its data directories
   111  		docker rm s3-minio
   112  		rm -rf /tmp/minio
   113  		rm -f /tmp/minio_config.yaml
   114  		# Code coverage files
   115  		rm -rf /tmp/cover* /tmp/unit*
   116  		go clean -i -r -x -testcache -modcache
   117  
   118  error-report:
   119  	@echo "Error messaging:"
   120  	@echo ""
   121  	@ag "gplog.Error|gplog.Fatal|ors.New|errors.Error|CheckClusterError|GpexpandFailureMessage =|errMsg :=" --ignore "*_test*" | grep -v "FatalOnError(err)" | grep -v ".Error()"
   122  
   123  warning-report:
   124  	@echo "Warning messaging:"
   125  	@echo ""
   126  	@ag "gplog.Warn" --ignore "*_test*"
   127  
   128  info-report:
   129  	@echo "Info and verbose messaging:"
   130  	@echo ""
   131  	@ag "gplog.Info|gplog.Verbose" --ignore "*_test*"
   132  
   133  test-s3-local: build install
   134  	${PWD}/plugins/generate_minio_config.sh
   135  	mkdir -p /tmp/minio/gpbackup-s3-test
   136  	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"
   137  	sleep 2 # Wait for minio server to start up
   138  	${PWD}/plugins/plugin_test.sh $(BIN_DIR)/gpbackup_s3_plugin /tmp/minio_config.yaml
   139  	docker stop s3-minio
   140  	docker rm s3-minio