11# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
22
3+ export PATH := $(abspath bin/) :${PATH}
4+
5+ # Setting SHELL to bash allows bash commands to be executed by recipes.
6+ # Options are set to exit when a recipe line exits non-zero or a piped command fails.
7+ SHELL = /usr/bin/env bash -o pipefail
8+ .SHELLFLAGS = -ec
9+
310# Default values for environment variables used in the Makefile
411KUBECONFIG ?= $(HOME ) /.kube/config
512TEST_KIND_CLUSTER ?= vault-secrets-reloader
613# Target image name
7- IMG ? = ghcr.io/bank-vaults/vault-secrets-reloader:dev
14+ CONTAINER_IMAGE_REF = ghcr.io/bank-vaults/vault-secrets-reloader:dev
815
9- # Operator image name
16+ # Operator and Webhook image name
1017OPERATOR_VERSION ?= latest
1118WEBHOOK_VERSION ?= latest
1219
13- # Setting SHELL to bash allows bash commands to be executed by recipes.
14- # Options are set to exit when a recipe line exits non-zero or a piped command fails.
15- SHELL = /usr/bin/env bash -o pipefail
16- .SHELLFLAGS = -ec
17-
1820# #@ General
1921
2022# Targets commented with ## will be visible in "make help" info.
@@ -25,74 +27,25 @@ default: help
2527help : # # Display this help
2628 @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
2729
28- # #@ Checks
29-
30- .PHONY : license-check
31- license-check : # # Run license check
32- $(LICENSEI ) check
33- $(LICENSEI ) header
34-
35- .PHONY : fmt
36- fmt : # # Run go fmt against code
37- $(GOLANGCI_LINT ) run --fix
38-
39- .PHONY : lint-go
40- lint-go : # Run golang lint check
41- $(GOLANGCI_LINT ) run $(if ${CI},--out-format github-actions,)
42-
43- .PHONY : lint-helm
44- lint-helm : # Run helm lint check
45- $(HELM ) lint deploy/charts/vault-secrets-reloader
46-
47- .PHONY : lint-yaml
48- lint-yaml :
49- $(YAMLLINT ) $(if ${CI},-f github,) --no-warnings .
50-
51- .PHONY : lint-docker
52- lint-docker : # Run Dockerfile lint check
53- $(HADOLINT ) Dockerfile
54-
55- .PHONY : lint
56- lint : lint-go lint-helm lint-yaml lint-docker # # Run lint checks
57-
58- .PHONY : test
59- test : # # Run tests
60- go clean -testcache
61- go test -race -v ./...
62-
63- .PHONY : test-e2e
64- test-e2e : # # Run acceptance tests. If running on a local kind cluster, run "make import-test" before this
65- go clean -testcache
66- go test -race -v -timeout 900s -tags e2e ./e2e
67-
68- .PHONY : test-e2e-local
69- test-e2e-local : container-image # # Run e2e tests locally
70- go clean -testcache
71- LOAD_IMAGE=${IMG} RELOADER_VERSION=dev OPERATOR_VERSION=$(OPERATOR_VERSION ) WEBHOOK_VERSION=$(WEBHOOK_VERSION ) LOG_VERBOSE=true ${MAKE} test-e2e
72-
7330# #@ Development
7431
75- .PHONY : run
76- run : # # Run manager from your host
77- go run main.go -log-level=debug -collector-sync-period=30s -reloader-run-period=1m
32+ .PHONY : up-kind
33+ up-kind : create-kind up # # Start kind development environment
7834
7935.PHONY : create-kind
8036create-kind : # # Create kind cluster
81- $(KIND ) create cluster --name $(TEST_KIND_CLUSTER )
82-
83- .PHONY : up-kind
84- up-kind : create-kind up # # Start kind development environment
37+ $(KIND_BIN ) create cluster --name $(TEST_KIND_CLUSTER )
8538
8639.PHONY : up
8740up : # # Start development environment
88- $(HELM ) upgrade --install vault-operator oci://ghcr.io/bank-vaults/helm-charts/vault-operator \
41+ $(HELM_BIN ) upgrade --install vault-operator oci://ghcr.io/bank-vaults/helm-charts/vault-operator \
8942 --set image.tag=latest \
9043 --set image.bankVaultsTag=latest \
9144 --wait
92- $( KUBECTL ) create namespace bank-vaults-infra --dry-run=client -o yaml | $( KUBECTL ) apply -f -
93- $( KUBECTL ) apply -f $(shell pwd) /e2e/deploy/vault/
45+ kubectl create namespace bank-vaults-infra --dry-run=client -o yaml | kubectl apply -f -
46+ kubectl apply -f $(shell pwd) /e2e/deploy/vault/
9447 sleep 60
95- $(HELM ) upgrade --install secrets-webhook oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook \
48+ $(HELM_BIN ) upgrade --install secrets-webhook oci://ghcr.io/bank-vaults/helm-charts/secrets-webhook \
9649 --set replicaCount=1 \
9750 --set image.tag=latest \
9851 --set image.pullPolicy=IfNotPresent \
@@ -102,42 +55,101 @@ up: ## Start development environment
10255
10356.PHONY : down
10457down : # # Destroy kind development environment
105- $(KIND ) delete cluster --name $(TEST_KIND_CLUSTER )
58+ $(KIND_BIN ) delete cluster --name $(TEST_KIND_CLUSTER )
10659
107- # #@ Build
60+ .PHONY : run
61+ run : # # Run manager from your host
62+ go run main.go -log-level=debug -collector-sync-period=30s -reloader-run-period=1m
10863
109- .PHONY : artifacts
110- artifacts : build container-image helm-chart # # Build artifacts
64+ # #@ Build
11165
11266.PHONY : build
11367build : # # Build manager binary
11468 @mkdir -p build
11569 go build -race -o build/vault-secrets-reloader .
11670
71+ .PHONY : artifacts
72+ artifacts : container-image helm-chart # # Build artifacts
73+
11774.PHONY : container-image
11875container-image : # # Build docker image
119- docker build -t ${IMG } .
76+ docker build -t ${CONTAINER_IMAGE_REF } .
12077
12178.PHONY : helm-chart
12279helm-chart : # # Build Helm chart
12380 @mkdir -p build
12481 helm package -d build/ deploy/charts/vault-secrets-reloader
12582
126- # #@ Autogeneration
83+ # #@ Checks
12784
128- .PHONY : gen-helm-docs
129- gen-helm-docs : # # Generate Helm chart documentation
130- $(HELM_DOCS ) -s file -c deploy/charts/ -t README.md.gotmpl
85+ .PHONY : check
86+ check : test lint # # Run lint checks and tests
87+
88+ .PHONY : test
89+ test : # # Run tests
90+ go clean -testcache
91+ go test -race -v ./...
92+
93+ .PHONY : test-e2e
94+ test-e2e : # # Run e2e tests
95+ go clean -testcache
96+ go test -race -v -timeout 900s -tags e2e ./e2e
97+
98+ .PHONY : test-e2e-local
99+ test-e2e-local : container-image # # Run e2e tests locally
100+ go clean -testcache
101+ LOAD_IMAGE=${CONTAINER_IMAGE_REF} RELOADER_VERSION=dev OPERATOR_VERSION=$(OPERATOR_VERSION ) WEBHOOK_VERSION=$(WEBHOOK_VERSION ) LOG_VERBOSE=true ${MAKE} test-e2e
102+
103+ .PHONY : lint
104+ lint : lint-go lint-helm lint-docker lint-yaml # # Run lint checks
105+
106+ .PHONY : lint-go
107+ lint-go : # Run golang lint check
108+ $(GOLANGCI_LINT_BIN ) run $(if ${CI},--out-format colored-line-number,)
109+
110+ .PHONY : lint-helm
111+ lint-helm : # Run helm lint check
112+ $(HELM_BIN ) lint deploy/charts/vault-secrets-reloader
113+
114+ .PHONY : lint-docker
115+ lint-docker : # Run Dockerfile lint check
116+ $(HADOLINT_BIN ) Dockerfile
117+
118+ .PHONY : lint-yaml
119+ lint-yaml :
120+ $(YAMLLINT_BIN ) $(if ${CI},-f github,) --no-warnings .
121+
122+ .PHONY : fmt
123+ fmt : # # Run go fmt against code
124+ $(GOLANGCI_LINT_BIN ) run --fix
125+
126+ .PHONY : license-check
127+ license-check : # # Run license check
128+ $(LICENSEI_BIN ) check
129+ $(LICENSEI_BIN ) header
130+
131+ # #@ Autogeneration
131132
132133.PHONY : generate
133134generate : gen-helm-docs # # Generate manifests, code, and docs resources
134135
136+ .PHONY : gen-helm-docs
137+ gen-helm-docs : # # Generate Helm chart documentation
138+ $(HELM_DOCS_BIN ) -s file -c deploy/charts/ -t README.md.gotmpl
139+
135140# #@ Deployment
136141
142+ .PHONY : deploy-kind
143+ deploy-kind : upload-kind deploy # # Deploy Reloder controller resources to the kind cluster
144+
145+ .PHONY : upload-kind
146+ upload-kind :
147+ $(KIND_BIN ) load docker-image ${CONTAINER_IMAGE_REF} --name $(TEST_KIND_CLUSTER ) # # Load docker image to kind cluster
148+
137149.PHONY : deploy
138150deploy : # # Deploy Reloader controller resources to the K8s cluster
139- $( KUBECTL ) create namespace bank-vaults-infra --dry-run=client -o yaml | $( KUBECTL ) apply -f -
140- $(HELM ) upgrade --install vault-secrets-reloader deploy/charts/vault-secrets-reloader \
151+ kubectl create namespace bank-vaults-infra --dry-run=client -o yaml | kubectl apply -f -
152+ $(HELM_BIN ) upgrade --install vault-secrets-reloader deploy/charts/vault-secrets-reloader \
141153 --set image.tag=dev \
142154 --set collectorSyncPeriod=30s \
143155 --set reloaderRunPeriod=1m \
@@ -147,71 +159,59 @@ deploy: ## Deploy Reloader controller resources to the K8s cluster
147159 --set env.VAULT_TLS_SECRET_NS=bank-vaults-infra \
148160 --namespace bank-vaults-infra
149161
150- .PHONY : upload-kind
151- upload-kind :
152- $(KIND ) load docker-image $(IMG ) --name $(TEST_KIND_CLUSTER ) # # Load docker image to kind cluster
153-
154- .PHONY : deploy-kind
155- deploy-kind : upload-kind deploy # # Deploy Reloder controller resources to the kind cluster
156-
157162.PHONY : undeploy
158163undeploy : # # Clean manager resources from the K8s cluster.
159- $(HELM ) uninstall vault-secrets-reloader --namespace bank-vaults-infra
164+ $(HELM_BIN ) uninstall vault-secrets-reloader --namespace bank-vaults-infra
160165
161166# #@ Dependencies
162167
163- # Dependency tool chain
164- GOLANGCI_VERSION = 1.53.3
165- LICENSEI_VERSION = 0.8.0
166- KIND_VERSION = 0.20.0
167- KUBECTL_VERSION = 1.28.3
168- HELM_DOCS_VERSION = 1.11.0
169-
170- # # Location to install dependencies to
171- LOCALBIN ?= $(shell pwd) /bin
172- $(LOCALBIN ) :
173- mkdir -p $(LOCALBIN )
174-
175- ENVTEST ?= $(or $(shell which setup-envtest) ,$(LOCALBIN ) /setup-envtest)
176- $(ENVTEST ) : $(LOCALBIN )
177- test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
178-
179- GOLANGCI_LINT ?= $(or $(shell which golangci-lint) ,$(LOCALBIN ) /golangci-lint)
180- $(GOLANGCI_LINT ) : $(LOCALBIN )
181- test -s $(LOCALBIN ) /golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_VERSION}
182-
183- HELM ?= $(or $(shell which helm) ,$(LOCALBIN ) /helm)
184- $(HELM ) : $(LOCALBIN )
185- test -s $(LOCALBIN ) /helm || curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | USE_SUDO=false HELM_INSTALL_DIR=$(LOCALBIN ) bash
186-
187- HELM_DOCS ?= $(or $(shell which helm-docs) ,$(LOCALBIN ) /helm-docs)
188- $(HELM_DOCS ) : $(LOCALBIN )
189- @if [ ! -s " $( LOCALBIN) /helm-docs" ]; then \
190- curl -L https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION} /helm-docs_${HELM_DOCS_VERSION} _$(shell uname) _x86_64.tar.gz | tar -zOxf - helm-docs > ./bin/helm-docs; \
191- chmod +x $(LOCALBIN ) /helm-docs; \
192- fi
193-
194- KIND ?= $(or $(shell which kind) ,$(LOCALBIN ) /kind)
195- $(KIND ) : $(LOCALBIN )
196- @if [ ! -s " $( LOCALBIN) /kind" ]; then \
197- curl -Lo $(LOCALBIN ) /kind https://kind.sigs.k8s.io/dl/v${KIND_VERSION} /kind-$(shell uname -s | tr '[:upper:]' '[:lower:]') -$(shell uname -m | sed -e "s/aarch64/arm64/; s/x86_64/amd64/") ; \
198- chmod +x $(LOCALBIN ) /kind; \
199- fi
200-
201- KUBECTL ?= $(or $(shell which kubectl) ,$(LOCALBIN ) /kubectl)
202- $(KUBECTL ) : $(LOCALBIN )
203- @if [ ! -s " $( LOCALBIN) /kubectl" ]; then \
204- curl -Lo $(LOCALBIN ) /kubectl https://dl.k8s.io/release/v${KUBECTL_VERSION} /bin/$(shell uname -s | tr '[:upper:]' '[:lower:]') /$(shell uname -m | sed -e "s/aarch64/arm64/; s/x86_64/amd64/") /kubectl; \
205- chmod +x $(LOCALBIN ) /kubectl; \
206- fi
207-
208- LICENSEI ?= $(or $(shell which licensei) ,$(LOCALBIN ) /licensei)
209- $(LICENSEI ) : $(LOCALBIN )
210- test -s $(LOCALBIN ) /licensei || curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | bash -s -- v${LICENSEI_VERSION}
168+ deps : bin/golangci-lint bin/licensei bin/kind bin/helm bin/helm-docs
169+ deps : # # Install dependencies
211170
212- # TODO: add support for hadolint and yamllint dependencies
213- HADOLINT ?= hadolint
214- YAMLLINT ?= yamllint
171+ # Dependency versions
172+ GOLANGCI_LINT_VERSION = 1.61.0
173+ LICENSEI_VERSION = 0.9.0
174+ KIND_VERSION = 0.24.0
175+ HELM_VERSION = 3.16.1
176+ HELM_DOCS_VERSION = 1.14.2
177+
178+ # Dependency binaries
179+ GOLANGCI_LINT_BIN := golangci-lint
180+ LICENSEI_BIN := licensei
181+ KIND_BIN := kind
182+ HELM_BIN := helm
183+ HELM_DOCS_BIN := helm-docs
215184
216- .PHONY : deps
217- deps : $(ENVTEST ) $(GOLANGCI_LINT ) $(HELM ) $(HELM_DOCS ) $(KIND ) $(KUBECTL ) $(LICENSEI ) # # Download and install dependencies
185+ # TODO: add support for hadolint and yamllint dependencies
186+ HADOLINT_BIN := hadolint
187+ YAMLLINT_BIN := yamllint
188+ # If we have "bin" dir, use those binaries instead
189+ ifneq ($(wildcard ./bin/.) ,)
190+ GOLANGCI_LINT_BIN := bin/$(GOLANGCI_LINT_BIN)
191+ LICENSEI_BIN := bin/$(LICENSEI_BIN)
192+ KIND_BIN := bin/$(KIND_BIN)
193+ HELM_BIN := bin/$(HELM_BIN)
194+ HELM_DOCS_BIN := bin/$(HELM_DOCS_BIN)
195+ endif
196+
197+ bin/golangci-lint :
198+ @mkdir -p bin
199+ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_LINT_VERSION}
200+
201+ bin/licensei :
202+ @mkdir -p bin
203+ curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | bash -s -- v${LICENSEI_VERSION}
204+ bin/kind :
205+ @mkdir -p bin
206+ curl -Lo bin/kind https://kind.sigs.k8s.io/dl/v${KIND_VERSION} /kind-$(shell uname -s | tr '[:upper:]' '[:lower:]') -$(shell uname -m | sed -e "s/aarch64/arm64/; s/x86_64/amd64/")
207+ @chmod +x bin/kind
208+
209+ bin/helm :
210+ @mkdir -p bin
211+ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | USE_SUDO=false HELM_INSTALL_DIR=bin DESIRED_VERSION=v$(HELM_VERSION ) bash
212+ @chmod +x bin/helm
213+
214+ bin/helm-docs :
215+ @mkdir -p bin
216+ curl -L https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION} /helm-docs_${HELM_DOCS_VERSION} _$(shell uname) _x86_64.tar.gz | tar -zOxf - helm-docs > ./bin/helm-docs
217+ @chmod +x bin/helm-docs
0 commit comments