-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (96 loc) · 3.55 KB
/
Copy pathMakefile
File metadata and controls
110 lines (96 loc) · 3.55 KB
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
# Project variables
PACKAGE = github.com/KongZ/authproxy
DOCKER_REGISTRY ?= 534625442569.dkr.ecr.ap-southeast-1.amazonaws.com
DOCKER_IMAGE = ${DOCKER_REGISTRY}/authproxy
# Build variables
BUILD_ARCH ?= linux/amd64
VERSION = $(shell git describe --tags --always --dirty)
COMMIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE = $(shell date +%FT%T%z)
LDFLAGS += -w -s -X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH} -X main.buildDate=${BUILD_DATE}
export CGO_ENABLED ?= 1
export GOOS = $(shell go env GOOS)
# export GO111MODULE=off
ifeq (${VERBOSE}, 1)
GOFLAGS += -v
endif
# Docker variables
ifeq ($(BUILD_ARCH), linux/amd64)
DOCKER_TAG = ${VERSION}
else
DOCKER_TAG = ${VERSION}-$(BUILD_ARCH)
endif
# chdir
CHDIR_SHELL := $(SHELL)
define chdir
$(eval _D=$(firstword $(1) $(@D)))
$($(MAKE): cd $(_D)) $(eval SHELL = cd $(_D); $(CHDIR_SHELL))
endef
.PHONY: build
build: ## Build all binaries
@echo "\033[0;30m\n🚜 Building..."
@go build ${GOFLAGS} -tags "${GOTAGS}" -ldflags "${LDFLAGS}" .
@echo "\033[0;32m\n🏃♂️ Running Go test..."
@go test -race -cover -v ./...
@echo "\033[0;34m\n👨⚕️ Running Staticcheck..."
@staticcheck -f stylish -fail -U1000 ./...
@echo "\033[0;33m\n👮♀️ Running Gosec..."
@gosec ./...
@echo "\033[0m"
.PHONY: build-debug
build-debug: GOFLAGS += -gcflags "all=-N -l"
build-debug: build ## Build a binary with remote debugging capabilities
.PHONY: docker
docker: ## Build a Docker image
@echo "Building architecture ${BUILD_ARCH}"
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} \
--platform $(BUILD_ARCH) \
--build-arg=VERSION=$(VERSION) \
--build-arg=COMMIT_HASH=$(COMMIT_HASH) \
--build-arg=BUILD_DATE=$(BUILD_DATE) \
-f Dockerfile .
.PHONY: docker-multi
docker-multi: BUILD_ARCH := $(strip $(BUILD_ARCH)),linux/arm64
docker-multi: ## Build a Docker image in multi-architect
@echo "Building architecture ${BUILD_ARCH}"
docker buildx build -t ${DOCKER_IMAGE}:${DOCKER_TAG} \
--platform=$(BUILD_ARCH) \
--build-arg=VERSION=$(VERSION) \
--build-arg=COMMIT_HASH=$(COMMIT_HASH) \
--build-arg=BUILD_DATE=$(BUILD_DATE) \
-f Dockerfile .
.PHONY: docker-multi-push
docker-multi-push: BUILD_ARCH := $(strip $(BUILD_ARCH)),linux/arm64
docker-multi-push: ## Build a Docker image in multi-architect and push to GCR
## @docker login ghcr.io -u USERNAME -p $(CR_PAT)
@echo "Building architecture ${BUILD_ARCH}"
docker buildx build -t ${DOCKER_IMAGE}:${DOCKER_TAG} \
--push \
--platform=$(BUILD_ARCH) \
--build-arg=VERSION=$(VERSION) \
--build-arg=COMMIT_HASH=$(COMMIT_HASH) \
--build-arg=BUILD_DATE=$(BUILD_DATE) \
-f Dockerfile .
release-%: ## Release a new version
git tag -m 'Release $*' $*
@echo "Version updated to $*!"
@echo
@echo "To push the changes execute the following:"
@echo
@echo "git push; git push origin $*"
.PHONY: patch
patch: ## Release a new patch version
@${MAKE} release-$(shell git describe --abbrev=0 --tags | awk -F'[ .]' '{print $$1"."$$2"."$$3+1}')
.PHONY: minor
minor: ## Release a new minor version
@${MAKE} release-$(shell git describe --abbrev=0 --tags | awk -F'[ .]' '{print $$1"."$$2+1".0"}')
.PHONY: major
major: ## Release a new major version
@${MAKE} release-$(shell git describe --abbrev=0 --tags | awk -F'[ .]' '{print $$1+1".0.0"}')
.PHONY: run ## Run the locally
run:
go run .
.PHONY: help
.DEFAULT_GOAL := help
help: # A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'