-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
269 lines (207 loc) · 10.4 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
KUBESERIAL_REGISTRY=ghcr.io/janekbaraniewski/kubeserial
DEVICE_MONITOR_REGISTRY=ghcr.io/janekbaraniewski/kubeserial-device-monitor
INJECTOR_WEBHOOK_REGISTRY=ghcr.io/janekbaraniewski/kubeserial-injector-webhook
TARGET_PLATFORMS=$(shell cat TARGET_PLATFORMS)
APP_VERSION?=$(shell git describe --dirty --tags --match "[0-9]*" )
CRDS_VERSION?=$(shell git describe --dirty --tags --match "crds*" | sed 's/crds-//')
DOCKERBUILD_PLATFORM_OPT=--platform
RELEASE_NAME ?= kubeserial
ENVTEST_K8S_VERSION = 1.23.3
MINIKUBE_PROFILE=kubeserial
ARM_PLATFORM=linux/arm64
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
include Makefile.build
##@ General
.PHONY: help
help: ## Display this help.
@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)
##@ Development
.PHONY: manifests-gen
manifests-gen: COPY_OR_DIFF=copy
manifests-gen: manifests-gen-script
.PHONY: check-manifests-gen
check-manifests-gen: COPY_OR_DIFF=diff
check-manifests-gen: manifests-gen-script
.PHONY: manifests-gen-script
manifests-gen-script:
@COPY_OR_DIFF=${COPY_OR_DIFF} ./hack/manifests-gen.sh
.PHONY: code-gen
code-gen: COPY_OR_DIFF=copy
code-gen: code-gen-script
.PHONY: check-code-gen
check-code-gen: COPY_OR_DIFF=diff
check-code-gen: code-gen-script
.PHONY: code-gen-script
code-gen-script:
@COPY_OR_DIFF=${COPY_OR_DIFF} ./hack/code-gen.sh
.PHONY: generate
generate: manifests-gen code-gen ## Generate files
.PHONY: check-generated
check-generated: check-code-gen check-manifests-gen
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: get-test-assets
get-test-assets:
@echo "Genereting test assets"
@./hack/get-test-assets.sh
.PHONY: test
test: fmt vet envtest-render-crds get-test-assets ## Run tests.
go test ./... -coverprofile coverage.txt.tmp -covermode atomic
@cat coverage.txt.tmp | grep -v "fake_api.go" > coverage.txt
@rm coverage.txt.tmp
@rm -r test-assets
.PHONY: test-fswatch
test-fswatch: ## Use fswatch to watch source files and run tests on chamnge
fswatch -or pkg Makefile Makefile.build cmd go.mod go.sum | xargs -n1 -I{} make test
.PHONY: envtest-render-crds
envtest-render-crds:
@rm -rf build/_output/kubeserial-crds || echo ""
@helm template charts/kubeserial-crds --name-template kubeserial --output-dir build/_output
.PHONY: lint
lint:
golangci-lint run
.PHONY: check
check: check-generated lint
check: ## Run linters and check code gen
# ENVTEST = $(shell pwd)/bin/setup-envtest
# .PHONY: envtest
# envtest: ## Download envtest-setup locally if necessary.
# $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
##@ Run
.PHONY: run
run: generate fmt vet ## Run codegen and start controller from your host.
go run ./cmd/manager/main.go
##@ Docker
.PHONY: docker-local
docker-local: kubeserial-docker-local device-monitor-docker-local injector-webhook-docker-local ## Build images for local dev
.PHONY: docker-all
docker-all: kubeserial-docker-all device-monitor-docker-all injector-webhook-docker-all
.PHONY: kubeserial-docker-local
kubeserial-docker-local: PLATFORMS?=$(ARM_PLATFORM)
kubeserial-docker-local: DOCKERBUILD_PLATFORM_OPT?=
kubeserial-docker-local: DOCKERBUILD_ACTION?=--load
kubeserial-docker-local: APP_VERSION ?= local
kubeserial-docker-local: kubeserial-docker ## Build image for local development, tag local, supports only builder platform
.PHONY: kubeserial-docker-all
kubeserial-docker-all: PLATFORMS=${TARGET_PLATFORMS}
kubeserial-docker-all: DOCKERBUILD_ACTION?=--push
kubeserial-docker-all: kubeserial-docker ## Build and push image for all target platforms
.PHONY: kubeserial-docker
kubeserial-docker: DOCKERFILE=Dockerfile
kubeserial-docker: REGISTRY=${KUBESERIAL_REGISTRY}
kubeserial-docker: DOCKERBUILD_EXTRA_OPTS?=--cache-to=type=registry,mode=max,ref=${KUBESERIAL_REGISTRY}:cache --cache-from ${KUBESERIAL_REGISTRY}:cache
kubeserial-docker:
docker buildx build . -f ${DOCKERFILE} ${DOCKERBUILD_EXTRA_OPTS} ${DOCKERBUILD_PLATFORM_OPT} ${PLATFORMS} -t $(REGISTRY):$(APP_VERSION) ${DOCKERBUILD_ACTION}
.PHONY: device-monitor-docker-local
device-monitor-docker-local: PLATFORMS?=$(ARM_PLATFORM)
device-monitor-docker-local: DOCKERBUILD_PLATFORM_OPT?=
device-monitor-docker-local: DOCKERBUILD_ACTION?=--load
device-monitor-docker-local: APP_VERSION ?= local
device-monitor-docker-local: device-monitor-docker ## Build image for local development, tag local, supports only builder platform
.PHONY: device-monitor-docker-all
device-monitor-docker-all: PLATFORMS=$(TARGET_PLATFORMS)
device-monitor-docker-all: DOCKERBUILD_ACTION?=--push
device-monitor-docker-all: device-monitor-docker ## Build and push image for all target platforms
.PHONY: device-monitor-docker
device-monitor-docker: DOCKERFILE=Dockerfile.monitor
device-monitor-docker: REGISTRY=${DEVICE_MONITOR_REGISTRY}
device-monitor-docker: DOCKERBUILD_EXTRA_OPTS=--cache-to=type=registry,mode=max,ref=${DEVICE_MONITOR_REGISTRY}:cache --cache-from ${DEVICE_MONITOR_REGISTRY}:cache
device-monitor-docker:
docker buildx build . -f ${DOCKERFILE} ${DOCKERBUILD_EXTRA_OPTS} ${DOCKERBUILD_PLATFORM_OPT} ${PLATFORMS} -t $(REGISTRY):$(APP_VERSION) ${DOCKERBUILD_ACTION}
.PHONY: injector-webhook-docker-local
injector-webhook-docker-local: PLATFORMS?=$(ARM_PLATFORM)
injector-webhook-docker-local: DOCKERBUILD_PLATFORM_OPT?=
injector-webhook-docker-local: DOCKERBUILD_ACTION?=--load
injector-webhook-docker-local: APP_VERSION ?= local
injector-webhook-docker-local: injector-webhook-docker ## Build image for local development, tag local, supports only builder platform
.PHONY: injector-webhook-docker-all
injector-webhook-docker-all: PLATFORMS=$(TARGET_PLATFORMS)
injector-webhook-docker-all: DOCKERBUILD_ACTION?=--push
injector-webhook-docker-all: injector-webhook-docker ## Build and push image for all target platforms
.PHONY: injector-webhook-docker
injector-webhook-docker: DOCKERFILE=Dockerfile.webhook
injector-webhook-docker: REGISTRY=${INJECTOR_WEBHOOK_REGISTRY}
injector-webhook-docker: DOCKERBUILD_EXTRA_OPTS=--cache-to=type=registry,mode=max,ref=${INJECTOR_WEBHOOK_REGISTRY}:cache --cache-from ${INJECTOR_WEBHOOK_REGISTRY}:cache
injector-webhook-docker:
docker buildx build . -f ${DOCKERFILE} ${DOCKERBUILD_EXTRA_OPTS} ${DOCKERBUILD_PLATFORM_OPT} ${PLATFORMS} -t $(REGISTRY):$(APP_VERSION) ${DOCKERBUILD_ACTION}
##@ Helm
.PHONY: update-kubeserial-chart-version
update-kubeserial-chart-version: CHART_PATH=./charts/kubeserial
update-kubeserial-chart-version:
@CHART_PATH=${CHART_PATH} VERSION=${APP_VERSION} ./hack/update-chart-version.sh
.PHONY: update-kubeserial-crds-chart-version
update-kubeserial-crds-chart-version: CHART_PATH=./charts/kubeserial-crds
update-kubeserial-crds-chart-version:
@CHART_PATH=${CHART_PATH} VERSION=${CRDS_VERSION} ./hack/update-chart-version.sh
.PHONY: helm-lint
helm-lint: ## Run chart-testing to lint kubeserial chart.
@ct lint --chart-dirs charts/ --check-version-increment=false
.PHONY: update-crds-labels
update-crds-labels:
@python3 ./hack/update-crd-metadata.py charts/kubeserial-crds/templates/app.kubeserial.com_kubeserials.yaml hack/crd_metadata_template.yaml
.PHONY: update-webhook-template
update-webhook-template:
@python3 ./hack/update-webhook-template.py charts/kubeserial/templates/webhooks.yaml hack/webhook_template.yaml
.PHONY: update-version
update-version: ## Update charts version.
update-version: update-kubeserial-crds-chart-version update-kubeserial-chart-version
##@ Kind
.PHONY: kind
kind: kind-create install-certmanager docker-local kind-load-images install-dev ## Create kind cluster, install certmanager, build and load images, install dev release.
kind-create:
kind create cluster --name kubeserial
.PHONY: install-certmanager
install-certmanager: ## Install cert-manager from jetstack/cert-manager
helm upgrade --install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.10.0 --set installCRDs=true
kind-load-images: ## Load images to kind cluster
kind load docker-image --name kubeserial ghcr.io/janekbaraniewski/kubeserial:${APP_VERSION}
kind load docker-image --name kubeserial ghcr.io/janekbaraniewski/kubeserial-device-monitor:${APP_VERSION}
kind load docker-image --name kubeserial ghcr.io/janekbaraniewski/kubeserial-injector-webhook:${APP_VERSION}
##@ Minikube
.PHONY: minikube
minikube: minikube-start minikube-build-controller-image minikube-build-monitor-image install-certmanager install-dev ## Start local cluster, build image and deploy
.PHONY: minikube-start
minikube-start: ## Start minikube cluster
@minikube -p ${MINIKUBE_PROFILE} start
.PHONY: minikube-set-context
minikube-set-context: ## Set context to use minikube cluster
@minikube -p ${MINIKUBE_PROFILE} update-context
.PHONY: minikube-build-controller-image
minikube-build-controller-image: DOCKERFILE=Dockerfile
minikube-build-controller-image: REGISTRY=${KUBESERIAL_REGISTRY}
minikube-build-controller-image: minikube-build-image
.PHONY: minikube-build-monitor-image
minikube-build-monitor-image: DOCKERFILE=Dockerfile.monitor
minikube-build-monitor-image: REGISTRY=${DEVICE_MONITOR_REGISTRY}
minikube-build-monitor-image: minikube-build-image
.PHONY: minikube-build-image
minikube-build-image: DOCKERBUILD_EXTRA_OPTS=--load
minikube-build-image:
@eval $$(minikube -p ${MINIKUBE_PROFILE} docker-env) ;\
docker buildx build . -f ${DOCKERFILE} ${DOCKERBUILD_EXTRA_OPTS} -t $(REGISTRY):$(APP_VERSION)
@echo "Finished building image ${REGISTRY}:${APP_VERSION}"
@echo "Available images:"
@eval $$(minikube -p ${MINIKUBE_PROFILE} docker-env) ;\
docker images
##@ Deployment
.PHONY: uninstall
uninstall: ## Uninstall release.
helm uninstall ${RELEASE_NAME}
.PHONY: deploy-dev
deploy-dev: manifests-gen update-version
helm upgrade --create-namespace --namespace kubeserial --install ${RELEASE_NAME}-crds ./charts/kubeserial-crds
helm upgrade --create-namespace --namespace kubeserial --install ${RELEASE_NAME} ./charts/kubeserial -f ./charts/kubeserial/values-local.yaml
.PHONY: install-dev
install-dev: update-version deploy-dev ## Install dev release in current context/namespace.
##@ Docs
.PHONY: docs-install-deps
docs-deps: ## Install mdbook (requires rust and cargo) + plugins
cargo install mdbook mdbook-mermaid mdbook-open-on-gh mdbook-toc
.PHONY: serve-docs
docs-serve: ## Build docs, start server and open in browser
cd docs && mdbook serve --open