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