-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·101 lines (82 loc) · 4.44 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
PROJECT := $(shell basename $(CURDIR))
current_dir = $(shell pwd)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
HASH := $(shell git rev-parse HEAD)
NAMESPACE := $(PROJECT)-$(BRANCH)
ifdef REGISTRY
REGISTRY := $(REGISTRY)
else
REGISTRY := localhost:5001
endif
# HELP
# This will output the help for each task
.PHONY: help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
binfolder:
mkdir -p $(HOME)/.local/bin/
cat $(HOME)/.bashrc | grep -qF ".local/bin/" || echo 'export PATH=$$PATH:$$HOME/.local/bin/' >> $(HOME)/.bashrc
kubectx:
kubectl config use-context kind-kind
# Build the container
build-container: ## Build the container
docker build -t $(PROJECT):$(BRANCH) .
push-container: test-cst ## Push container to local registry
docker tag $(PROJECT):$(BRANCH) $(REGISTRY)/$(PROJECT):$(BRANCH)
docker push $(REGISTRY)/$(PROJECT):$(BRANCH)
run-container: ## Run container for the test
docker run -i -t --rm --name="$(PROJECT)" $(PROJECT):$(BRANCH)
stop-container: ## Stop and remove a running container
docker stop $(PROJECT); docker rm $(PROJECT)
clean: ## Clean container
docker stop $(PROJECT); docker rm $(PROJECT); docker rmi $(PROJECT):$(BRANCH)
install-kind: binfolder ## kind minimal kubernetes for local development
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.14.0/kind-linux-amd64 ;\
chmod +x ./kind ;\
mv ./kind $(HOME)/.local/bin/kind
install-kubectl: binfolder ## Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
chmod +x kubectl && mv kubectl $(HOME)/.local/bin/kubectl
install-helm: binfolder ## Install helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
install-cst: binfolder ## Install container structure test
curl -LO https://storage.googleapis.com/container-structure-test/latest/container-structure-test-linux-amd64 && \
chmod +x container-structure-test-linux-amd64 && mv container-structure-test-linux-amd64 $(HOME)/.local/bin/container-structure-test
deploy-app: kubectx ## Deploy application to kind kubernetes
helm upgrade --install -n $(NAMESPACE) --create-namespace -f helm/values.yaml $(PROJECT) ./helm \
--set image.tag=$(BRANCH) \
--set image.repository=$(REGISTRY)/$(PROJECT) \
--set serviceMonitor.enabled=true
deploy-cluster: kubectx ## Deploy kind cluster with local registry
sh -c cluster/cluster-local-registry.sh
deploy-ingress: kubectx ## Deploy nginx ingress controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
deploy-metricserver: kubectx ## Deploy metric server for enable HPA.
helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
helm upgrade --install metrics-server -n kube-system metrics-server/metrics-server --set args[0]=--kubelet-insecure-tls
deploy-opa: kubectx ## Deploy open policy agent
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper/release-3.8/deploy/gatekeeper.yaml
deploy-prometheus: kubectx ## Deploy prometheus operator
kubectl create -f https://github.com/prometheus-operator/prometheus-operator/raw/v0.57.0/bundle.yaml
kubectl apply -f cluster/prometheus.yaml
delete-app: kubectx ## Delete application from kind kubernetes
helm uninstall -n $(NAMESPACE) $(PROJECT)
delete-cluster: kubectx ## Destroy kind cluter
kind delete cluster
delete-ingress: kubectx ## Delete nginx ingress controller
kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
delete-metricserver: kubectx ## Delete metric server
helm uninstall -n kube-system metrics-server
delete-opa: kubectx ## Deploy open policy agent
kubectl delete -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper/release-3.8/deploy/gatekeeper.yaml
delete-prometheus: kubectx ## Delete prometheus operator
kubectl delete -f https://github.com/prometheus-operator/prometheus-operator/raw/v0.57.0/bundle.yaml
kubectl apply -f cluster/prometheus.yaml
perform-test: ## Performance test
docker run --add-host=chart-example.local:172.17.0.1 --rm jordi/ab -v 2 http://chart-example.local/enrich?ip=1.1.1.1
test-app: kubectx ## Test deployed app
helm test -n $(PROJECT)
test-cst: ## Test container structure
container-structure-test test --image $(REGISTRY)/$(PROJECT):$(BRANCH) \
--config test/cst.yaml