This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
forked from bank-vaults/bank-vaults
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
246 lines (176 loc) · 7.38 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
export PATH := $(abspath bin/):${PATH}
CONTAINER_IMAGE_REF = ghcr.io/banzaicloud/bank-vaults:dev
# Dependency versions
GOLANGCI_VERSION = 1.53.3
LICENSEI_VERSION = 0.8.0
.PHONY: build
build: ## Build binary
@mkdir -p build
go build -race -o build/ ./cmd/bank-vaults
.PHONY: lint
lint: lint-go lint-docker lint-yaml
lint: ## Run linters
.PHONY: lint-go
lint-go:
golangci-lint run $(if ${CI},--out-format github-actions,)
.PHONY: lint-docker
lint-docker:
hadolint Dockerfile
.PHONY: lint-yaml
lint-yaml:
yamllint $(if ${CI},-f github,) --no-warnings .
.PHONY: fmt
fmt: ## Format code
golangci-lint run --fix
.PHONY: license-check
license-check: ## Run license check
licensei check
licensei header
deps: bin/golangci-lint bin/licensei
deps: ## Install dependencies
bin/golangci-lint:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_VERSION}
bin/licensei:
@mkdir -p bin
curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | bash -s -- v${LICENSEI_VERSION}
OS = $(shell uname)
DOCKER_BUILD_EXTRA_ARGS ?=
# Export HOST_NETWORK=1 if you want to build the docker images with host network (useful when using some VPNs)
ifeq (${HOST_NETWORK}, 1)
DOCKER_BUILD_EXTRA_ARGS += --network host
endif
# Project variables
PACKAGE = github.com/banzaicloud/bank-vaults
BINARY_NAME ?= bank-vaults
DOCKER_REGISTRY ?= ghcr.io/banzaicloud
DOCKER_IMAGE = ${DOCKER_REGISTRY}/bank-vaults
WEBHOOK_DOCKER_IMAGE = ${DOCKER_REGISTRY}/vault-secrets-webhook
# Build variables
BUILD_DIR ?= build
BUILD_PACKAGE = ${PACKAGE}/cmd/...
VERSION ?= $(shell echo `git symbolic-ref -q --short HEAD || git describe --tags --exact-match` | tr '[/]' '-')
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date +%FT%T%z)
LDFLAGS += -X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH} -X main.buildDate=${BUILD_DATE}
export CGO_ENABLED ?= 1
export GOOS = $(shell go env GOOS)
ifeq (${VERBOSE}, 1)
GOARGS += -v
endif
# Docker variables
DOCKER_TAG ?= ${VERSION}
# Dependency versions
GOTESTSUM_VERSION = 0.4.0
GOLANG_VERSION = 1.19.2
.PHONY: docker
docker: ## Build a Docker image
docker build ${DOCKER_BUILD_EXTRA_ARGS} -t ${DOCKER_IMAGE}:${DOCKER_TAG} -f Dockerfile .
ifeq (${DOCKER_LATEST}, 1)
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
endif
.PHONY: image
image: ## Build an OCI image with buildah
buildah bud -t ${DOCKER_IMAGE}:${DOCKER_TAG} -f Dockerfile .
ifeq (${IMAGE_LATEST}, 1)
buildah tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
endif
.PHONY: docker-push
docker-push: ## Push a Docker image
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
ifeq (${DOCKER_LATEST}, 1)
docker push ${DOCKER_IMAGE}:latest
endif
.PHONY: test-%
test-%: ## Run a specific test suite
@${MAKE} VERBOSE=0 GOTAGS=$* test
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: clean
clean: ## Clean builds
rm -rf ${BUILD_DIR}/
.PHONY: clear
clear: ## Clear the working area and the project
rm -rf bin/ vendor/
.PHONY: docker-build
docker-build: ## Builds go binary in docker image
docker run -it -v $(PWD):/go/src/${PACKAGE} -w /go/src/${PACKAGE} golang:${GOLANG_VERSION}-alpine go build -o ${BINARY_NAME}_linux ${BUILD_PACKAGE}
.PHONY: debug
debug: GOARGS += -gcflags "-N -l"
debug: BINARY_NAME := ${BINARY_NAME}-debug
debug: build ## Builds binary package
.PHONY: debug-docker
debug-docker: debug ## Builds binary package
docker build -t ghcr.io/banzaicloud/${BINARY_NAME}:debug -f Dockerfile.dev .
.PHONY: lint-sdk
lint-sdk: bin/golangci-lint ## Run linter
cd pkg/sdk && ../../bin/golangci-lint run --disable varnamelen,ireturn,nosnakecase,exhaustruct,nonamedreturns,nilnil,contextcheck,maintidx,dupword,gosec,gomoddirectives,gci,gofumpt,gofmt,goimports,revive,staticcheck
.PHONY: fix-sdk
fix-sdk: bin/golangci-lint ## Fix lint violations
cd pkg/sdk && ../../bin/golangci-lint run --fix --disable varnamelen,ireturn,nosnakecase,exhaustruct,nonamedreturns,nilnil,contextcheck,maintidx,dupword,gosec,gomoddirectives,gci,gofumpt,gofmt,goimports,revive,staticcheck
.PHONY: check
check: test-integration test-sdk-integration ## Run tests and linters
bin/gotestsum: bin/gotestsum-${GOTESTSUM_VERSION}
@ln -sf gotestsum-${GOTESTSUM_VERSION} bin/gotestsum
bin/gotestsum-${GOTESTSUM_VERSION}:
@mkdir -p bin
curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_${OS}_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum-${GOTESTSUM_VERSION} && chmod +x ./bin/gotestsum-${GOTESTSUM_VERSION}
TEST_PKGS ?= ./...
TEST_REPORT_NAME ?= results.xml
.PHONY: test
test: TEST_REPORT ?= main
test: TEST_FORMAT ?= short
test: SHELL = /bin/bash
test: bin/gotestsum ## Run tests
@mkdir -p ${BUILD_DIR}/test_results/${TEST_REPORT}
bin/gotestsum --no-summary=skipped --junitfile ${BUILD_DIR}/test_results/${TEST_REPORT}/${TEST_REPORT_NAME} --format ${TEST_FORMAT} -- $(filter-out -v,${GOARGS}) $(if ${TEST_PKGS},${TEST_PKGS},./...)
test-sdk: TEST_REPORT ?= sdk
test-sdk: TEST_FORMAT ?= short
test-sdk: SHELL = /bin/bash
test-sdk: bin/gotestsum ## Run SDK tests
@mkdir -p ${BUILD_DIR}/test_results/${TEST_REPORT}
cd pkg/sdk && ../../bin/gotestsum --no-summary=skipped --junitfile ../../${BUILD_DIR}/test_results/${TEST_REPORT}/${TEST_REPORT_NAME} --format ${TEST_FORMAT} -- $(filter-out -v,${GOARGS}) $(if ${TEST_PKGS},${TEST_PKGS},./...)
.PHONY: test-all
test-all: ## Run all tests
@${MAKE} GOARGS="${GOARGS} -run .\*" TEST_REPORT=all test
.PHONY: test-integration
test-integration: ## Run integration tests
@${MAKE} GOARGS="${GOARGS} -tags=integration" TEST_REPORT=integration test
.PHONY: test-sdk-integration
test-sdk-integration: ## Run integration tests in sdk package
@${MAKE} GOARGS="${GOARGS} -tags=integration" TEST_REPORT=integration test-sdk
bin/jq: bin/jq-${JQ_VERSION}
@ln -sf jq-${JQ_VERSION} bin/jq
bin/jq-${JQ_VERSION}:
@mkdir -p bin
ifeq (${OS}, Darwin)
curl -L https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-osx-amd64 > ./bin/jq-${JQ_VERSION} && chmod +x ./bin/jq-${JQ_VERSION}
endif
ifeq (${OS}, Linux)
curl -L https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64 > ./bin/jq-${JQ_VERSION} && chmod +x ./bin/jq-${JQ_VERSION}
endif
.PHONY: list
list: ## List all make targets
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# Variable outputting/exporting rules
var-%: ; @echo $($*)
varexport-%: ; @echo $*=$($*)