-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
667 lines (564 loc) · 23.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
.SHELLFLAGS = -ec
.ONESHELL:
.DEFAULT_GOAL := help
IMG_BACKEND ?= localhost:5001/stackx-backend:0.0.0
IMG_CONTROLLER ?= localhost:5001/stackx-controller:0.0.0
IMG_FRONTEND ?= localhost:5001/stackx-frontend:0.0.0
K8S_VERSION = 1.25.3
OS := $(shell uname -s | tr A-Z a-z)
SCHEMA_URL := https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
##@ General
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\n\033[48;5;17m\033[1m\stackx Makefile\033[0m\n\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: dev start-dev start
dev: kind-start local-registry docker-build-dev docker-push-dev kind-context dep-deploy deploy-all ## Starts complete development environment.
start: start-dev
start-dev: dev ## 🚀 (start) Starts Minikube, build & deploy ALL for dev (hot reload).
tmux: ## Start a tmux session and within the development environment.
@cd ../stackx-backend && ./hack/tmux.sh
@printf "\033[36m make $@\033[0m: Finished\n"
##@ Backend (back, b)
.PHONY: b-build
b-build: back-build
.PHONY: back-build
back-build: ## Build Golang binary from code.
@printf "\nBACKEND - Run go build ..."
@cd ../stackx-backend && go build -o stackx-backend main.go
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-doc
b-doc: back-doc
.PHONY: back-doc
back-doc: ## Build Swagger/OpenAPI documentation.
@printf "\nBACKEND - Generating swagger docs ..."
@cd ../stackx-backend && swag init -g main.go --output docs
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-deploy-local
b-deploy-kind: back-deploy-local
.PHONY: back-deploy-local
back-deploy-local: ## Deploy to local K8s cluster.
@printf "\nBACKEND - Deploy to local K8s ..."
@kubectl config set-context kind
@cd ../stackx-backend && kubectl apply -f ci/manifest.yaml
@kubectl rollout restart deployment stackx-backend -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-docker-build
b-docker-build: back-docker-build
.PHONY: back-docker-build
back-docker-build: ## Build docker image.
@printf "\nBACKEND - Build docker image ${IMG_BACKEND} ..."
@cd ../stackx-backend && docker build -t ${IMG_BACKEND} .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-docker-buildx
b-docker-buildx: back-docker-buildx
.PHONY: back-docker-buildx
back-docker-buildx: ## Build and push multi-arch images with buildx.
@printf "\nBACKEND - Build docker image ${IMG_BACKEND} ..."
@cd ../stackx-backend && docker buildx build --push --platform linux/amd64,linux/arm64 --tag ${IMG_BACKEND} .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-docker-build-dev
b-docker-build-dev: back-docker-build-dev
.PHONY: back-docker-build-dev
back-docker-build-dev: ## Build development docker image with hot-reloading.
@printf "\nBACKEND - Build custom dev image for minikube with hot-reloading ..."
@printf "\nBACKEND: Copy stackx-controller (dependency) ...\n"
@cd ../stackx-backend && rm -rf ./stackx-controller && cp -rf ../stackx-controller . && docker build -t ${IMG_BACKEND} -f hack/Dockerfile .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-docker-push
b-docker-push: back-docker-push
.PHONY: back-docker-push
back-docker-push: ## Push Docker image to registry.
@printf "\nBACKEND - Push image to registry ..."
docker push ${IMG_BACKEND}
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-docker-push-dev
b-docker-push-dev: back-docker-push-dev
.PHONY: back-docker-push-dev
back-docker-push-dev: ## Push dev Docker image to local registry.
@printf "\nBACKEND - Push custom dev image to local registry ..."
docker push ${IMG_BACKEND}
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-fmt
b-fmt: back-fmt
.PHONY: back-fmt
back-fmt: ## Format your code with go fmt.
@printf "\nBACKEND - Run go fmt to format your code ..."
@cd ../stackx-backend && go fmt ./...
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-go-get
b-go-get: back-go-get
.PHONY: back-go-get
back-go-get: ## Run go get -u for your go.mod file.
@printf "\nBACKEND - Run go get -u to update all deps ..."
@cd ../stackx-backend && go get -u
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-k-logs
b-k-logs: back-kubectl-logs
.PHONY: b-kubectl-logs
b-kubectl-logs: back-kubectl-logs
.PHONY: back-kubectl-logs
back-kubectl-logs: ## Blocks until canceled (Ctrl-C): Show logs of pods.
@printf "\nBLOCKING: Showing logs of stackx-backend ...."
@kubectl logs deploy/stackx-backend -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-k-port
b-k-port: back-kubectl-port
.PHONY: b-kubectl-port
b-kubectl-port: back-kubectl-port
.PHONY: backend-kubectl-port
back-kubectl-port: ## Blocks until canceled (Ctrl+C): Port-Forward --> 8080
@printf "\nBLOCKING: Port-forwarding to localhost:8080 ...\n"
@kubectl port-forward svc/stackx-backend 8080:80 -n stackx
@printf "\n\033[36m make $@\033[0m: Finished\n"
.PHONY: b-run
b-run: back-run
.PHONY: back-run
back-run: ## Runs your Golang code.
@printf "\nBACKEND - Run go run ./main.go ...\n"
@cd ../stackx-backend && go run ./main.go
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-test
b-test: back-test
.PHONY: back-test
back-test: ## Runs your Golang tests.
@printf "\nBACKEND - Run go test ./...\n"
@cd ../stackx-backend && go test ./...
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: b-vet
b-vet: back-vet
.PHONY: back-vet
back-vet: ## Run go vet against code.
@printf "\nBACKEND - Run go test ./..."
@cd ../stackx-backend && go vet ./...
@printf "\033[36m make $@\033[0m: Finished\n"
##@ Controller (ctrl, c)
.PHONY: ctrl-build
ctrl-build: ## Build Golang code.
@printf "\nCONTROLLER - Run go build ..."
@cd ../stackx-controller && go build -o stackx-controller main.go
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-doc
ctrl-doc: ## Build Swagger/OpenAPI documentation.
@printf "\nCONTROLLER - Generating swagger docs ..."
@cd ../stackx-controller && swag init -g main.go --output docs
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-deploy-local
ctrl-deploy-local: ## Deploy to local K8s cluster.
@printf "\nCONTROLLER - Deploy to local K8s ..."
@kubectl config set-context kind
@cd ../stackx-controller && kubectl apply -f ci/manifest.yaml
@kubectl rollout restart deployment stackx-controller -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-docker-build
ctrl-docker-build: ## Build docker image.
@printf "\nCONTROLLER - Build docker image ${IMG_CONTROLLER} ..."
@cd ../stackx-controller && docker build -t ${IMG_CONTROLLER} .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-docker-buildx
ctrl-docker-buildx: ## Build and push multi-arch images with buildx.
@printf "\nCONTROLLER - Build docker image ${IMG_BACKEND} ..."
@cd ../stackx-controller && docker buildx build --push --platform linux/amd64,linux/arm64 --tag ${IMG_BACKEND} .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-docker-build-dev
ctrl-docker-build-dev: ## Build development docker image with hot-reloading.
@printf "\nCONTROLLER - Build custom dev image for minikube with hot-reloading ..."
@cd ../stackx-controller && docker build -t ${IMG_CONTROLLER} -f hack/Dockerfile .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-docker-push
ctrl-docker-push: ## Push Docker image to registry.
@printf "\nCONTROLLER - Build custom dev image for minikube with hot-reloading ..."
docker push ${IMG_CONTROLLER}
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: c-docker-push-dev
c-docker-push-dev: ctrl-docker-push-dev
.PHONY: ctrl-docker-push-dev
ctrl-docker-push-dev: ## Push dev Docker image to local registry.
@printf "\nCONTROLLER - Push custom dev image to local registry ..."
docker push ${IMG_CONTROLLER}
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-fmt
ctrl-fmt: ## Run go fmt against code.
@printf "\nCONTROLLER - Run go fmt to format your code ..."
@cd ../stackx-controller && go fmt ./...
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-go-get
ctrl-go-get: ## Run go get -u on your go.mod file.
@printf "\nCONTROLLER - Run go get -u to update all deps ..."
@cd ../stackx-controller && go get -u
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-kubectl-logs
ctrl-kubectl-logs: ## Blocks until canceled (Ctrl-C): Show logs of pods.
@printf "\nCONTROLLER: Showing logs of stackx-backend ...."
@kubectl logs deploy/stackx-controller -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-kubectl-port
ctrl-kubectl-port: ## Blocks until canceled (Ctrl+C): Port-Forward --> 8080
@printf "\nCONTROLLER: Port-forwarding to localhost:8080 ...\n"
@kubectl port-forward svc/stackx-controller 8080:80 -n stackx
@printf "\n\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-run
ctrl-run: ## Runs your Golang code.
@printf "\nCONTROLLER - Run go run ./main.go ..."
@cd ../stackx-controller && go run ./main.go
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-test
ctrl-test: ## Runs your Golang tests.
@printf "\nCONTROLLER - Run go test ./..."
@cd ../stackx-controller && go test ./...
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: ctrl-vet
ctrl-vet: ## Run go vet against code.
@printf "\nCONTROLLER - Run go test ./..."
@cd ../stackx-controller && go vet ./...
@printf "\033[36m make $@\033[0m: Finished\n"
##@ Frontend (front, f)
.PHONY: front-build
front-build: ## Build Javascript code.
@printf "\nFRONTEND - Run npm build ..."
@cd ../stackx-frontend && npm run build
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-deploy-local
front-deploy-local: ## Deploy to local K8s cluster.
@printf "\nFRONTEND - Deploy to local K8s ..."
@kubectl config set-context kind
@cd ../stackx-front && kubectl apply -f ci/manifest.yaml
@kubectl rollout restart deployment stackx-frontend -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-docker-build
front-docker-build: ## Build docker image.
@printf "\nFRONTEND - Build docker image ${IMG_FRONTEND} ..."
@cd ../stackx-frontend && docker build -t ${IMG_FRONTEND} .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-docker-buildx
front-docker-buildx: ## Build and push multi-arch images with buildx.
@printf "\nFRONTEND - Build docker image ${IMG_BACKEND} ..."
@cd ../stackx-frontend && docker buildx build --push --platform linux/amd64,linux/arm64 --tag ${IMG_BACKEND} .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-docker-build-dev
front-docker-build-dev: ## Build development docker image with hot-reloading.
@printf "\nFRONTEND - Build custom dev image for minikube with hot-reloading ..."
@cd ../stackx-frontend && docker build -t ${IMG_FRONTEND} -f hack/Dockerfile .
@printf "\033[36m make $@\033[0m: Finished\n"
.front: front-docker-push
front-docker-push: ## Push Docker image to registry.
@printf "\nFRONTEND - Build custom dev image for minikube with hot-reloading ..."
docker push ${IMG_FRONTEND}
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: f-docker-push-dev
f-docker-push-dev: front-docker-push-dev
.PHONY: front-docker-push-dev
front-docker-push-dev: ## Push dev Docker image to local registry.
@printf "\nFRONTEND - Push custom dev image to local registry ..."
docker push ${IMG_FRONTEND}
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-fmt
front-fmt: ## Run npm run fmt against code.
@printf "\nFRONTEND - Run go fmt to format your code ..."
@cd ../stackx-frontend && npm run fmt
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-kubectl-logs
front-kubectl-logs: ## Blocks until canceled (Ctrl-C): Show logs of pods.
@printf "\nFRONTEND: Showing logs of stackx-backend ...."
@kubectl logs deploy/stackx-frontend -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-kubectl-port
front-kubectl-port: ## Blocks until canceled (Ctrl+C): Port-Forward --> 3000
@printf "\nFRONTEND: Port-forwarding to localhost:3000 ...\n"
@kubectl port-forward svc/stackx-frontend 3000:80 -n stackx
@printf "\n\033[36m make $@\033[0m: Finished\n"
.PHONY: front-start
front-start: ## Starts / runs your Javascript code.
@printf "\nFRONTEND - Run npm run start ..."
@cd ../stackx-frontend && npm run start
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: front-test
front-test: ## Runs your Javascript tests.
@printf "\nFRONTEND - Run npm run test ..."
@cd ../stackx-frontend && npm run test
@printf "\033[36m make $@\033[0m: Finished\n"
##@ K8s / Helm
.PHONY: ct
ct: ## Run chart-testing for your chart.
@printf "\nHELM - Run chart-testing ..."
@ct lint --config ci/ct.yaml --chart-yaml-schema ci/chart_schema.yaml --lint-conf ci/lintconf.yaml
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: d-deploy
d-deploy: dep-deploy
.PHONY: dep-deploy
dep-deploy: ## Deploy depencencies (flux, tf-controller) to cluster.
@printf "\nDeploy dependencies (flux, tf-controller) ..."
@printf "\nDeploy flux ...\n"
@flux install
@printf "\nDeploy flux completed.\n"
@printf "\nDeploy tf-controller ..."
@helm upgrade -i tf-controller tf-controller/tf-controller --namespace flux-system
@printf "\nDeploy tf-controller completed.\n"
@printf "\nDeploy stackx-controller CRDs ...\n"
@cd ../stackx-controller && make install
@printf "\nDeploy stackx-controller CRDs completed.\n"
@printf "\nDeploy ingress-nginx controller ...\n"
@kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
@kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
@printf "\nDeploy ingress-nginx controller completed.\n"
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: h-lint
h-lint: helm-lint
.PHONY: helm-lint
helm-lint: ## Run helm lint for your chart.
@printf "\nHELM - Run helm lint ..."
ifneq ("$(wildcard ci/values-test.yaml)","")
@helm lint chart/$(CHART) -f ci/values-test.yaml
else
@printf "Fallback using unit-test values (if any) ...\n"
@helm lint chart/$(CHART) -f chart/$(CHART)/tests/values-test.yaml --strict
endif
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: kubeconform
kubeconform: ## Run kubeconform on your chart.
@printf "\nHELM - Run kubeconform ..."
@rm -rf manifests/*
@helm template chart/$(CHART) --output-dir manifests -f ci/values-test.yaml
@find manifests -name '*.yaml' | grep -v crd | xargs kubeconform -kubernetes-version $(KUBE_VERSION) --strict --schema-location ${SCHEMA_URL} --ignore-missing-schemas
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: kubesec
kubesec: ## Run kubesec on your chart.
@printf "\nHELM - Run kubesec ..."
@helm template chart/$(CHART) -f ci/values-test.yaml | kubesec scan -
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: kubescore
kubescore: ## Run kubescore on your chart.
@printf "\nHELM - Run kubescore ..."
@helm template chart/$(CHART) -f ci/values-test.yaml | kube-score score --exit-one-on-warning -o ci --ignore-test container-image-pull-policy -
@echo "kube-score exited with $(.SHELLSTATUS)"
@printf "\033[36m make $@\033[0m: Finished\n"
##@ Kind
.PHONY: kind-start
kind-start: ## Starts a new Kind cluster.
@printf "\nStarting kind cluster ..."
@kind create cluster --image kindest/node:v${K8S_VERSION} --name stackx --config ci/kind.yaml
#@cat ci/kind.yaml | sed "s|hostPath: .*|hostPath: $(dirname $$(pwd))/|" - | kind create cluster --image kindest/node:v${K8S_VERSION} --name stackx --config -
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: kind-delete
kind-delete: ## Deletes the Kind cluster.
@printf "\nDelete kind cluster ..."
@kind delete cluster --name stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: kind-context
kind-context: ## Switch Kubeconfig context to kind.
@printf "\nSwitch Kube Context ..."
@kind get kubeconfig --name stackx > $(HOME)/.kube/kind.yaml
@kubectl config set-context ".kube/kind-kind"
@printf "\033[36m make $@\033[0m: Finished\n"
##@ Minikube (minikube, mk)
.PHONY: mk-context
mk-context: minikube-context
.PHONY: minikube-context
minikube-context: ## Switch Kubeconfig context to minikube.
@printf "\nSwitch Kube Context ..."
@minikube update-context -p stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: mk-delete
mk-delete: minikube-delete
.PHONY: minikube-delete
minikube-delete: ## Delete the Minikube cluster.
@printf "\nRemove / Delete all minikube resources ..."
@minikube delete --all
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: mk-destroy
mk-destroy: minikube-destroy
.PHONY: minikube-destroy
minikube-destroy: ## Destroy and purge the Minikube cluster.
@printf "\nDestroy and purge all minikube resources ..."
@minikube delete --all --purge
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: mk-start
mk-start: minikube-start
.PHONY: minikube-start
minikube-start: ## Starts a new Minikube cluster.
@printf "\nStarting minikube cluster ..."
@minikube start --driver=docker --cpus=4 --memory=8192 --nodes 2 -p stackx --kubernetes-version=v${K8S_VERSION} --mount-string="$(shell dirname $$(pwd))/:/tmp/git" --mount
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: stop
stop: minikube-stop
.PHONY: mk-stop
mk-stop: minikube-stop
.PHONY: minikube-stop
minikube-stop: ## (stop) Stopping the Minikube cluster.
@printf "\nStopping minikube cluster ..."
@minikube stop -p stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: mk-load
mk-load: minikube-load
.PHONY: minikube-load
minikube-load: ## Loads all docker images into Minikube.
@printf "\nLoad ALL images into minikube cluster ... (this will take a while)"
@minikube image load ${IMG_BACKEND} -p stackx
@minikube image load ${IMG_CONTROLLER} -p stackx
@minikube image load ${IMG_FRONTEND} -p stackx
@printf "\n\033[36m make $@\033[0m: Finished\n"
##@ Terraform (tf, t)
.PHONY: t-apply
t-apply: tf-apply
.PHONY: tf-apply
tf-apply: ## Run terraform apply for your code.
@printf "\nTERRAFORM - Run terraform apply ..."
@terraform apply -auto-approve
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-clean
t-clean: tf-clean
.PHONY: tf-clean
tf-clean: ## Remove lockfiles and terraform states.
@printf "\nTERRAFORM - Cleanup state and lockfiles ..."
@rm -rf .terraform examples/.terraform examples/all/.terraform examples/non-k8s/.terraform tests/.terraform
@rm -f terraform.tfstate* examples/terraform.tfstate* examples/all/terraform.tfstate* examples/non-k8s/terraform.tfstate*
@rm -f .terraform.lock.hcl examples/.terraform.lock.hcl examples/all/.terraform.lock.hcl examples/non-k8s/.terraform.lock.hcl tests/.terraform.lock.hcl
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-destroy
t-destroy: tf-destroy
.PHONY: tf-destroy
tf-destroy: ## Run terraform destroy to delete all resources.
@printf "\nTERRAFORM - Run terraform destroy ..."
@terraform destroy -auto-approve
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-fmt
t-fmt: tf-fmt
.PHONY: tf-fmt
tf-fmt: ## Run terraform fmt to format your HCL code.
@printf "\nTERRAFORM - Run terraform fmt ..."
@terraform fmt -recursive
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-init
t-init: tf-init
.PHONY: tf-init
tf-init: ## Run terraform init for your code.
@printf "\nTERRAFORM - Run terraform init ..."
@terraform init
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: tflint
tflint: tf-lint
t-lint: tf-lint
.PHONY: t-lint
t-lint: tf-lint
.PHONY: tf-lint
tf-lint: ## Run tflint for your code.
@printf "\nTERRAFORM - Run tflint ..."
@tflint .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: tfsec
tfsec: tf-tfsec
.PHONY: t-tfsec
t-tfsec: tf-tfsec
.PHONY: tf-tfsec
tf-tfsec: ## Run tfsec for your code.
@printf "\nTERRAFORM - Run tfsec ..."
@tfsec .
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-local
t-local: tf-local-start
.PHONY: tf-local
tf-local: tf-local-start
.PHONY: tf-local-start
tf-local-start: ## Run localstack
@printf "\nLOCALSTACK - Run localstack (detached in the background) ..."
@localstack start -d
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-localf
t-localf: tf-local-startf
.PHONY: tf-localf
tf-localf: tf-local-startf
.PHONY: tf-local-startf
tf-local-startf: ## Run localstack in foreground
@printf "\nBLOCKING - Run localstack (attach, blocking) ..."
@localstack start
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: tf-local-stop
tf-local-stop: ## Stop localstack
@printf "\nLOCALSTACK - Stop localstack ..."
@localstack stop
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-plan
t-plan: tf-plan
.PHONY: tf-plan
tf-plan: ## Run terraform plan for your code.
@printf "\nTERRAFORM - Run terraform plan ..."
@terraform plan
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: t-test
t-test: tf-test
.PHONY: tf-test
tf-test: tf-test-init ## Run terratest for your code.
@printf "\nTERRAFORM - Run terraform test ..."
@terraform test -verbose
@cd tests && go test -v -count 1 -short -timeout "30m" -parallel 16 `go list ./...`
@printf "\033[36m make $@\033[0m: Finished\n"
tf-test-init:
ifeq (,$(wildcard ./tests/go.mod))
cd tests && go mod init $(shell basename $(CURDIR))
endif
.PHONY: t-validate
t-validate: tf-validate
.PHONY: tf-validate
tf-validate: ## Run terraform validate for some basic HCL validation.
@printf "\nTERRAFORM - Run terraform validate ..."
@terraform validate
@printf "\033[36m make $@\033[0m: Finished\n"
##@ Docker
.PHONY: local-registry
local-registry: ## Start local registry.
@./hack/local-registry.sh
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: docker-build
docker-build: back-docker-build ctrl-docker-build front-docker-build ## Build all Docker images.
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: docker-build-dev
docker-build-dev: back-docker-build-dev ctrl-docker-build-dev front-docker-build-dev ## Build all development Docker images.
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: docker-push
docker-push: back-docker-push ctrl-docker-push front-docker-push ## Push all Docker images to registry.
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: docker-push-dev
docker-push-dev: back-docker-push-dev ctrl-docker-push-dev front-docker-push-dev ## Push all dev Docker images to local registry.
@printf "\033[36m make $@\033[0m: Finished\n"
##@ ALL
.PHONY: purge
purge: clean-all
.PHONY: clean-all
clean-all: minikube-destroy ## 🗑️ (clean, destroy, purge) Clean EVERYTHING (Docker, Minikube, Kind, binaries, ...)
@printf "\nCleaning all ..."
@kind delete cluster --name stackx
@docker system prune -a -f
@docker images purge
@docker stop $(docker ps -a -q)
@docker rmi $(docker images -a -q) -f
@docker rm $(docker ps -a -q)
@docker volume prune -f
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: deploy-all
deploy-all: ## Deploy all apps to local K8s cluster.
@printf "\nDeploy ALL to local K8s ..."
@printf "stackx-controller ..."
@cd ../stackx-controller
@kubectl apply -f ../stackx-controller/hack/manifest-minikube.yaml
@kubectl rollout restart deployment stackx-controller -n stackx
@printf "stackx-backend ..."
@cd ../stackx-backend
@kubectl apply -f ../stackx-backend/hack/manifest-minikube.yaml
@kubectl rollout restart deployment stackx-backend -n stackx
@printf "stackx-frontend ..."
@cd ../stackx-frontend
@kubectl apply -f ../stackx-frontend/ci/manifest.yaml
@kubectl rollout restart deployment stackx-frontend -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"
.PHONY: logs
logs: ## Tail ALL logs with kubetail
@printf "\nTail ALL logs with kubetail ..."
@ kubetail '(backend|controller|frontend)' -e regex -n stackx
@printf "\033[36m make $@\033[0m: Finished\n"