-
Notifications
You must be signed in to change notification settings - Fork 97
/
Makefile
52 lines (38 loc) · 1.94 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
DOCKER_ACCOUNT = lesovsky
PROGRAM_NAME = pgcenter
PKG_PATH = github.com/lesovsky/pgcenter
COMMIT=$(shell git rev-parse --short HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TAG=$(shell git describe --tags |cut -d- -f1)
LDFLAGS = -ldflags "-X ${PKG_PATH}/internal/version.gitTag=${TAG} -X ${PKG_PATH}/internal/version.gitCommit=${COMMIT} -X ${PKG_PATH}/internal/version.gitBranch=${BRANCH}"
.PHONY: help clean dep build install uninstall
.DEFAULT_GOAL := help
help: ## Display this help screen.
@echo "Makefile available targets:"
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " * \033[36m%-15s\033[0m %s\n", $$1, $$2}'
clean: ## Clean build directory.
rm -f ./bin/${PROGRAM_NAME}
rmdir ./bin
dep: ## Download the dependencies.
go mod download
lint: dep ## Lint the source files
golangci-lint run --timeout 5m -E golint -e '(struct field|type|method|func) [a-zA-Z`]+ should be [a-zA-Z`]+'
gosec -quiet ./...
test: dep ## Run tests
go test -race -p 1 -timeout 300s -coverprofile=.test_coverage.txt ./... && \
go tool cover -func=.test_coverage.txt | tail -n1 | awk '{print "Total test coverage: " $$3}'
@rm .test_coverage.txt
build: dep ## Build pgcenter executable.
mkdir -p ./bin
CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} go build ${LDFLAGS} -o bin/${PROGRAM_NAME} ./cmd
install: ## Install pgcenter executable into /usr/bin directory.
install -pm 755 bin/${PROGRAM_NAME} /usr/bin/${PROGRAM_NAME}
uninstall: ## Uninstall pgcenter executable from /usr/bin directory.
rm -f /usr/bin/${PROGRAM_NAME}
docker-build: ## Build docker image
docker build -t ${DOCKER_ACCOUNT}/${PROGRAM_NAME}:${TAG} .
docker tag ${DOCKER_ACCOUNT}/${PROGRAM_NAME}:${TAG} ${DOCKER_ACCOUNT}/${PROGRAM_NAME}:latest
docker image prune --force --filter label=stage=intermediate
docker-push: ## Push docker image to registry
docker push ${DOCKER_ACCOUNT}/${PROGRAM_NAME}:${TAG}
docker push ${DOCKER_ACCOUNT}/${PROGRAM_NAME}:latest