-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathMakefile
More file actions
356 lines (301 loc) · 11.7 KB
/
Copy pathMakefile
File metadata and controls
356 lines (301 loc) · 11.7 KB
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
# Makefile for managing the Helm charts
MAKEFLAGS += --silent
SHELL := /bin/bash
chartPath := $(if $(chartPath),$(chartPath),charts/camunda-platform-*)
chartVersion = $(shell grep -Po '(?<=^version: ).+' $(chartPath)/Chart.yaml)
releaseName = camunda-platform-test
#########################################################
######### Go.
#########################################################
#
# Tests.
#
# Binaries.
#
.PHONY: build.deployer
build.deployer:
cd scripts/camunda-deployer && go mod tidy && go build .
.PHONY: build.prepare-helm-values
build.prepare-helm-values:
cd scripts/prepare-helm-values && go mod tidy && go build .
.PHONY: build.deploy-camunda
build.deploy-camunda:
cd scripts/deploy-camunda && go mod tidy && go build .
.PHONY: install.deployer
install.deployer:
cd scripts/camunda-deployer && go mod tidy && go install .
.PHONY: install.prepare-helm-values
install.prepare-helm-values:
cd scripts/prepare-helm-values && go mod tidy && go install .
.PHONY: install.deploy-camunda
install.deploy-camunda:
cd scripts/deploy-camunda && go mod tidy && go install .
.PHONY: build.vault-secret-mapper
build.vault-secret-mapper:
cd scripts/vault-secret-mapper && go mod tidy && go build .
.PHONY: install.vault-secret-mapper
install.vault-secret-mapper:
cd scripts/vault-secret-mapper && go mod tidy && go install .
.PHONY: build.ci-result-cache
build.ci-result-cache:
cd scripts/ci-result-cache && go mod tidy && go build .
.PHONY: install.ci-result-cache
install.ci-result-cache:
cd scripts/ci-result-cache && go mod tidy && go install .
.PHONY: build.release-tools
build.release-tools:
cd scripts/release-tools && go mod tidy && go build .
.PHONY: install.release-tools
install.release-tools:
cd scripts/release-tools && go mod tidy && go install .
.PHONY: build.dx-tooling
build.dx-tooling:
make build.deployer
make build.prepare-helm-values
make build.deploy-camunda
make build.vault-secret-mapper
make build.release-tools
.PHONY: install.dx-tooling
install.dx-tooling:
make install.deployer
make install.prepare-helm-values
make install.deploy-camunda
make install.vault-secret-mapper
make install.release-tools
@if command -v asdf >/dev/null 2>&1; then \
echo "asdf detected, reshimming..."; \
asdf reshim golang; \
fi
define go_test_run
find $(chartPath) -name "go.mod" -exec dirname {} \; |\
while read chart_dir; do\
echo "\n[$@] Chart dir: $${chart_dir}";\
cd $$(git rev-parse --show-toplevel);\
cd "$${chart_dir}";\
$(1);\
done
endef
# go.test: runs the tests without updating the golden files (runs checks against golden files)
.PHONY: go.test
go.test: helm.dependency-update
@$(call go_test_run, go test ./...)
@echo "\n[$@] Matrix package: registry validator + snapshot drift + lifecycle fixtures"
# Intentionally cross-version: walks all charts/*/test/ci/ regardless of chartPath (YAML parse only, fast).
@cd scripts/deploy-camunda && go test -timeout 2m ./matrix/
# go.test-golden-updated: runs the tests with updating the golden files
.PHONY: go.test-golden-updated
go.test-golden-updated: helm.dependency-update
@$(call go_test_run, go test ./... -args -update-golden)
.PHONY: go.update-golden-only-cleanup
go.update-golden-only-cleanup: helm.dependency-update
@$(call go_test_run, (\
echo "Delete golden files ..."; \
find . -name "*golden*.yaml" -delete; \
echo "Generate golden files ..."; \
go test ./...$(APP) -run '^TestGolden.+$$' -args -update-golden \
))
.PHONY: go.update-golden-only-lite
go.update-golden-only-lite:
@$(call go_test_run, go test ./...$(APP) -run '^TestGolden.+$$' -args -update-golden)
@$(MAKE) go.update-registry-golden
# go.update-registry-golden: refresh charts/<v>/test/ci/registry-snapshot.yaml for every
# chart version that has a composable registry. Runs the matrix-package golden test
# in update mode, which writes the compiled CITestConfig view back to disk.
.PHONY: go.update-registry-golden
go.update-registry-golden:
@echo "\n[$@] Updating registry snapshots in charts/<v>/test/ci/registry-snapshot.yaml"
@cd scripts/deploy-camunda && go test ./matrix/ -run TestRegistryGolden -update-golden
# go.update-golden-only: update the golden files only without the rest of the tests
.PHONY: go.update-golden-only
go.update-golden-only: helm.dependency-update go.update-golden-only-lite
# go.fmt: runs the gofmt in order to format all go files
.PHONY: go.fmt
go.fmt:
@$(call go_test_run, go fmt ./...)
@diff=$$(git status --porcelain | grep -F ".go" || true)
@if [ -n "$${diff}" ]; then\
echo "Some files are not following the go format ($${diff}), run gofmt and fix your files.";\
exit 1;\
fi
#
# Helpers.
# go.addlicense-install: installs the addlicense tool
.PHONY: go.addlicense-install
go.addlicense-install:
go install github.com/google/addlicense@v1.0.0
# go.addlicense-run: adds license headers to go files
.PHONY: go.addlicense-run
go.addlicense-run:
addlicense -c 'Camunda Services GmbH' -l apache charts/$(chartPath)/test/**/*.go
# go.addlicense-check: checks that the go files contain license header
.PHONY: go.addlicense-check
go.addlicense-check:
addlicense -check -l apache charts/$(chartPath)/test/**/*.go
#########################################################
######### Tools
#########################################################
# Add asdf plugins.
.tools.asdf-plugins-add:
@# Add plugins from .tool-versions file within the repo.
@# If the plugin is already installed asdf exits with 2, so grep is used to handle that.
@for plugin in $$(awk '{print $$1}' .tool-versions); do \
echo "$${plugin}"; \
asdf plugin add $${plugin} 2>&1 | (grep "already added" && exit 0); \
done
# Install tools via asdf.
tools.asdf-install: .tools.asdf-plugins-add
asdf install
# This target will be mainly used in the CI to update the images tag from camunda-platform repo
.PHONY: tools.update-values-file-image-tag
tools.update-values-file-image-tag:
@bash scripts/update-values-file-image-tag.sh
.PHONY: tools.zbctl-topology
tools.zbctl-topology:
kubectl exec svc/$(releaseName)-zeebe-gateway -- zbctl --insecure status
#########################################################
######### HELM
#########################################################
# helm.repos-add: add Helm repos needed by the charts
.PHONY: helm.repos-add
helm.repos-add:
@for repo_args in \
"camunda https://helm.camunda.io" ; \
do \
success=false; \
for i in 1 2 3; do \
if helm repo add $$repo_args --force-update; then \
success=true; break; \
fi; \
if [ $$i -lt 3 ]; then \
echo "⚠️ helm repo add $$repo_args failed (attempt $$i/3), retrying in 5s..." >&2; \
sleep 5; \
fi; \
done; \
if [ "$$success" != "true" ]; then \
echo "❌ helm repo add $$repo_args failed after 3 attempts" >&2; \
exit 1; \
fi; \
done
@helm repo update
# helm.dependency-update: update and downloads the dependencies for the Helm chart
.PHONY: helm.dependency-update
helm.dependency-update:
find $(chartPath) -name Chart.yaml -exec dirname {} \; | while read chart_dir; do\
echo "[$@] Chart dir: $${chart_dir}";\
helm dependency update $${chart_dir};\
done
# helm.lint: verify that the chart is well-formed.
.PHONY: helm.lint
helm.lint:
echo "[$@] Chart dir: $(chartPath)"
helm lint --strict $(chartPath)
# helm.lint: verify that the chart is well-formed.
.PHONY: helm.lint-all
helm.lint-all:
find $(chartPath) -name Chart.yaml -exec dirname {} \; | while read chart_dir; do\
$(MAKE) chartPath=$${chart_dir} helm.lint;\
done
# helm.install: install the local chart into the current kubernetes cluster/namespace
.PHONY: helm.install
helm.install: helm.dependency-update
helm install $(releaseName) $(chartPath)
# helm.uninstall: uninstall the chart and removes all related pvc's
.PHONY: helm.uninstall
helm.uninstall:
-helm uninstall $(releaseName)
-kubectl delete pvc -l app.kubernetes.io/instance=$(releaseName)
-kubectl delete pvc -l release=$(releaseName)
# helm.dry-run: run an install dry-run with the local chart
.PHONY: helm.dry-run
helm.dry-run: helm.dependency-update
helm install $(releaseName) $(chartPath) --dry-run
# helm.template: show all rendered templates for the local chart
.PHONY: helm.template
helm.template: helm.dependency-update
helm template $(releaseName) $(chartPath)
# helm.readme-update: generate readme from values file
.PHONY: helm.readme-update
helm.readme-update:
set -x; for chart_dir in $(chartPath); do\
test "camunda-platform-8.2" = "$$(basename $${chart_dir})" && continue;\
[[ "$$(basename $${chart_dir})" != *camunda-platform* ]] && continue;\
echo "\n[$@] Chart dir: $${chart_dir}";\
readme-generator \
--values "$${chart_dir}/values.yaml" \
--readme "$${chart_dir}/README.md";\
done
# helm.schema-update: generate schema from values file
.PHONY: helm.schema-update
# TODO: Once 8.7 is released, remove "alpha" name from the excluded versions.
helm.schema-update:
for chart_dir in $(chartPath); do \
excluded_charts="keycloak|postgres|elasticsearch"; \
if echo "$${chart_dir}" | grep -qE "$${excluded_charts}"; then \
echo "\n[$@] Chart dir: $${chart_dir}";\
echo "[$@] This chart version shouldnt autogenerate schema"; \
continue; \
fi; \
excluded_versions="camunda-platform-(8\.(2|3|4|5|6|7)|alpha)$$"; \
if echo "$${chart_dir}" | grep -qE "$${excluded_versions}"; then \
echo "\n[$@] Chart dir: $${chart_dir}";\
echo "[$@] This chart version doesn't have schema"; \
continue; \
fi; \
echo "\n[$@] Chart dir: $${chart_dir}"; \
readme-generator \
--values "$${chart_dir}/values.yaml" \
--schema "$${chart_dir}/values.schema.json"; \
if [ ! -f "$${chart_dir}/values.schema.extra.json" ]; then \
echo "[$@] No extra schema to merge"; \
continue; \
fi; \
echo "[$@] Merging with extra schema"; \
jq --indent 4 -s 'reduce .[] as $$obj ({}; . * $$obj)' \
"$${chart_dir}/values.schema.json" \
"$${chart_dir}/values.schema.extra.json" > "$${chart_dir}/values.schema.tmp.json" \
&& mv "$${chart_dir}/values.schema.tmp.json" "$${chart_dir}/values.schema.json"; \
done
# helm.get-images: list all images in the chart.
.PHONY: helm.get-images
helm.get-images:
export CHART_SOURCE="$(chartSource)"; \
export CHART_VERSION="$(chartVersion)"; \
export CHART_VALUES_DIR="$(chartPath)/"; \
bash -x scripts/list-chart-images.sh;
#########################################################
######### Release
#########################################################
.PHONY: .release.bump-chart-version
.release.bump-chart-version:
@bash scripts/bump-chart-version.sh
.PHONY: release.bump-chart-version-and-commit
release.bump-chart-version-and-commit: .release.bump-chart-version
git add $(chartPath);\
git commit -m "chore: bump camunda-platform chart version to $(chartVersion)"
.PHONY: release.generate-notes
release.generate-notes: install.release-tools
for chart_dir in $(chartPath); do\
echo "\n[$@] Chart dir: $${chart_dir}";\
release-tools release-notes --main "$${chart_dir}";\
done
.PHONY: release.generate-notes-footer
release.generate-notes-footer: install.release-tools helm.dependency-update
for chart_dir in $(chartPath); do\
echo "\n[$@] Chart dir: $${chart_dir}";\
release-tools release-notes --footer "$${chart_dir}";\
done
.PHONY: release.generate-and-commit
release.generate-and-commit: release.generate-notes
git add $(chartPath);\
git commit -m "chore: add generated files for camunda-platform $(chartVersion)"
.PHONY: release.verify-components-version
release.verify-components-version:
@bash scripts/verify-components-version.sh
.PHONY: release.set-prs-version-label
release.set-prs-version-label:
@bash scripts/set-prs-version-label.sh
#########################################################
######### Precommit
#########################################################
.PHONY: precommit.chores
precommit.chores: helm.lint helm.readme-update helm.schema-update go.update-golden-only-lite