-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
219 lines (168 loc) · 5.68 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
# https://makefiletutorial.com/
-include env.ini
ifndef CI
PLATFORMS?=linux/amd64
BUILDX_ARGS?=--load
else
PLATFORMS?=linux/amd64,linux/arm64
BUILDX_ARGS?=--push
endif
.EXPORT_ALL_VARIABLES:
DOCKERFILE := ./Dockerfile
TAG ?= $(shell cat TAG)
IMAGE ?= wallarm/sidecar-controller
CONTROLLER_IMAGE = $(IMAGE):$(TAG)
COMMIT_SHA ?= git-$(shell git rev-parse --short HEAD)
### Versions used to build controller image
###
ALPINE_VERSION = 3.20
GOLANG_VERSION = 1.22.5
### Variables used in tests
###
INJECTION_STRATEGY ?= single
REGISTRY ?= wallarm
### Contribution routines
###
EXEC := docker-compose exec -w /mnt/kubernetes/sidecar kubernetes
KUBECTL := $(EXEC) kubectl
HELM := $(EXEC) helm
BASH := $(EXEC) bash -c
POD_NAME := $(KUBECTL) get pods -o name -l app.kubernetes.io/component=controller | cut -d '/' -f 2
POD_EXEC = $(KUBECTL) exec -it $(shell $(POD_NAME)) --
init: cluster-start
@$(HELM) repo add jetstack https://charts.jetstack.io/
@$(HELM) repo update jetstack
@$(HELM) upgrade --install cert-manager jetstack/cert-manager --set installCRDs=true -n cert-manager --version v1.11.1 --create-namespace --wait
@$(HELM) upgrade --install --wait wallarm-sidecar ./helm -f ./helm/values.dev.yaml $(HELMARGS)
@$(KUBECTL) wait pods -n default -l app.kubernetes.io/component=controller --for condition=Ready --timeout=90s
@$(BASH) 'exec kubectl exec -it $$(kubectl get pods -o name -l app.kubernetes.io/component=controller | cut -d '/' -f 2) -- apk add git gcc libc-dev'
@$(BASH) 'exec kubectl exec -it $$(kubectl get pods -o name -l app.kubernetes.io/component=controller | cut -d '/' -f 2) -- go mod download'
bash:
@$(EXEC) bash
status:
@echo ===================== CLUSTERS =====================
@$(KUBECTL) config get-contexts
@echo ======================= PODS =======================
@$(KUBECTL) get pods -A
pod-sh:
@$(POD_EXEC) sh
pod-run:
@$(POD_EXEC) go run `ls cmd/*.go | grep -v _test.go` \
--listen :8443 \
--config /etc/controller/config.yaml \
--template /data/files/template.yaml.tpl \
--tls-cert-file /etc/controller/tls/tls.crt \
--tls-key-file /etc/controller/tls/tls.key \
--log-level trace \
--log-format text-color
pod-test:
@$(POD_EXEC) go test cmd/*_test.go
clean stop:
@$(BASH) 'docker ps -q | xargs docker stop || true'
@$(BASH) 'docker ps -a -q | xargs docker rm || true'
@$(BASH) 'docker volume ls -q | xargs docker volume rm || true'
@make $(MAKEFLAGS) cluster-down
clean-all:
@echo REMOVING VOLUME $(shell docker volume rm dind)
@echo REMOVING VOLUME $(shell docker volume rm registry)
### Helm routines
###
HELMARGS := --set "config.wallarm.api.token=$(WALLARM_API_TOKEN)" \
--set "config.wallarm.api.host=$(WALLARM_API_HOST)" \
--set "config.wallarm.api.nodeGroup=$(NODE_GROUP_NAME)" \
helm-template:
@$(HELM) template wallarm-sidecar ./helm -f ./helm/values.dev.yaml $(HELMARGS) --debug
helm-install:
@$(HELM) upgrade --install wallarm-sidecar ./helm -f ./helm/values.dev.yaml $(HELMARGS)
helm-diff:
@$(HELM) diff upgrade --debug --allow-unreleased wallarm-sidecar ./helm -f ./helm/values.dev.yaml $(HELMARGS)
helm-upgrade:
@$(HELM) upgrade wallarm-sidecar ./helm -f ./helm/values.dev.yaml $(HELMARGS)
helm-delete:
@$(HELM) uninstall wallarm-sidecar
.PHONY: helm-*
### Development
###
fmt:
@go fmt ./...
vet:
@go vet ./...
test: fmt vet
@go test -v ./...
.PHONY: fmt vet test
### Build
###
setup_buildx:
docker buildx rm multi-arch || true
docker buildx create \
--name multi-arch \
--platform linux/amd64,linux/arm64 \
--driver docker-container \
--use
build: setup_buildx
docker buildx build \
--file Dockerfile \
--platform=$(PLATFORMS) \
--build-arg ALPINE_VERSION="$(ALPINE_VERSION)" \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg CONTAINER_VERSION="$(TAG)" \
--build-arg COMMIT_SHA="$(COMMIT_SHA)" \
--force-rm --no-cache --progress=plain \
--tag $(CONTROLLER_IMAGE) $(BUILDX_ARGS) .
push rmi:
@docker $@ $(CONTROLLER_IMAGE)
dive:
@dive $(CONTROLLER_IMAGE)
.PHONY: build push rmi dive
### Smoke test routines
###
### Run smoke tests (expects access to a working Kind Kubernetes cluster).
###
smoke-test:
@test/smoke/run-smoke-suite.sh
### Crate Kind Kubernetes cluster and run smoke tests using kind
###
kind-smoke-test:
@test/smoke/run.sh
.PHONY: smoke-test kind-smoke-test
### Cluster routines
###
TARBALL := .tmp.image.tar
cluster-export-image:
@echo 'Putting image into kubernetes-accessible registry (local operation)'
@docker save $(IMAGE) > $(TARBALL)
@docker cp $(TARBALL) kubernetes:/$(TARBALL)
@rm $(TARBALL)
@docker-compose exec kubernetes docker load --input /$(TARBALL)
@docker-compose exec kubernetes rm /$(TARBALL)
@docker-compose exec kubernetes docker tag $(IMAGE) registry/$(IMAGE)
@docker-compose exec kubernetes docker push registry/$(IMAGE)
@docker-compose exec kubernetes docker rmi $(IMAGE) registry/$(IMAGE)
cluster-start:
@docker-compose build --progress plain
@docker-compose up -d
@sleep 3
@docker-compose exec kubernetes bash -c \
'test "$$(kubectl version -o yaml | grep platform | wc -l)" == 2 && echo CLUSTER EXISTS || routines.py create'
cluster-down:
@docker-compose down
cluster-stop:
@docker-compose stop
cluster-pause:
@docker-compose pause
cluster-unpause:
@docker-compose unpause
.PHONY: cluster-*
### Integration test routines
###
integration-test:
@$(KUBECTL) wait pods -n pytest --all --for=condition=Ready
@$(BASH) 'exec kubectl exec -n pytest -it $$(kubectl get pods -n pytest -o name | cut -d '/' -f 2) -- pytest -n 6 -rs helm/test'
.PHONY: integration-*
### Chart testing routines
###
ct-install:
@$(CURDIR)/helm/test/run_chart_tests.sh
ct-upgrade:
@CT_MODE="upgrade" $(CURDIR)/helm/test/run_chart_tests.sh
.PHONY: ct-*