-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
400 lines (337 loc) · 17.5 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
export PATH := $(abspath bin/):${PATH}
FORMATTING_BEGIN_YELLOW = \033[0;33m
FORMATTING_BEGIN_BLUE = \033[36m
FORMATTING_END = \033[0m
FOCUS =
MDLINTER_IMAGE = ghcr.io/igorshubovych/markdownlint-cli@sha256:2e22b4979347f70e0768e3fef1a459578b75d7966e4b1a6500712b05c5139476
# Explicitly set architecture on arm, since werf currently does not support building of images for any other platform
# besides linux/amd64 (e.g. relevant for mac m1).
PLATFORM_NAME := $(shell uname -m)
OS_NAME := $(shell uname)
ifneq ($(filter arm%,$(PLATFORM_NAME)),)
export WERF_PLATFORM=linux/amd64
endif
# Set platform for deps
ifeq ($(OS_NAME), Linux)
JQ_PLATFORM = linux64
YQ_PLATFORM = linux
TRDL_PLATFORM = linux
GH_PLATFORM = linux
else ifeq ($(OS_NAME), Darwin)
JQ_PLATFORM = osx-amd64
YQ_PLATFORM = darwin
TRDL_PLATFORM = darwin
GH_PLATFORM = macOS
endif
JQ_VERSION = 1.6
# Set arch for deps
ifeq ($(PLATFORM_NAME), x86_64)
YQ_ARCH = amd64
CRANE_ARCH = x86_64
TRDL_ARCH = amd64
CRANE_ARCH = x86_64
GH_ARCH = amd64
else ifeq ($(PLATFORM_NAME), arm64)
YQ_ARCH = arm64
CRANE_ARCH = arm64
TRDL_ARCH = arm64
CRANE_ARCH = arm64
GH_ARCH = arm64
endif
# Set testing path for tests-modules
ifeq ($(FOCUS),)
TESTS_PATH = ./modules/... ./global-hooks/... ./ee/modules/... ./ee/fe/modules/... ./ee/be/modules/... ./ee/se/modules/...
else
CE_MODULES = $(shell find ./modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(CE_MODULES),)
CE_MODULES_RECURSE = ${CE_MODULES}/...
endif
EE_MODULES = $(shell find ./ee/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(EE_MODULES),)
EE_MODULES_RECURSE = ${EE_MODULES}/...
endif
FE_MODULES = $(shell find ./ee/fe/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(FE_MODULES),)
FE_MODULES_RECURSE = ${FE_MODULES}/...
endif
BE_MODULES = $(shell find ./ee/be/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(FE_MODULES),)
BE_MODULES_RECURSE = ${BE_MODULES}/...
endif
SE_MODULES = $(shell find ./ee/se/modules -maxdepth 1 -regex ".*[0-9]-${FOCUS}")
ifneq ($(FE_MODULES),)
SE_MODULES_RECURSE = ${SE_MODULES}/...
endif
TESTS_PATH = ${CE_MODULES_RECURSE} ${EE_MODULES_RECURSE} ${FE_MODULES_RECURSE} ${BE_MODULES_RECURSE} ${SE_MODULES_RECURSE}
endif
# Set host arch & OS for golang-based programs, e.g. Prometheus
ifneq (, $(shell which go))
GOHOSTARCH := $(shell go env GOHOSTARCH)
GOHOSTOS := $(shell go env GOHOSTOS)
endif
help:
@printf -- "${FORMATTING_BEGIN_BLUE}%s${FORMATTING_END}\n" \
"" \
" ██████╗░███████╗░█████╗░██╗░░██╗██╗░░██╗░█████╗░██╗░░░██╗░██████╗███████╗" \
" ██╔══██╗██╔════╝██╔══██╗██║░██╔╝██║░░██║██╔══██╗██║░░░██║██╔════╝██╔════╝" \
" ██║░░██║█████╗░░██║░░╚═╝█████═╝░███████║██║░░██║██║░░░██║╚█████╗░█████╗░░" \
" ██║░░██║██╔══╝░░██║░░██╗██╔═██╗░██╔══██║██║░░██║██║░░░██║░╚═══██╗██╔══╝░░" \
" ██████╔╝███████╗╚█████╔╝██║░╚██╗██║░░██║╚█████╔╝╚██████╔╝██████╔╝███████╗" \
" ╚═════╝░╚══════╝░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░╚════╝░░╚═════╝░╚═════╝░╚══════╝" \
"" \
"-----------------------------------------------------------------------------------" \
""
@awk 'BEGIN {\
FS = ":.*##"; \
printf "Usage: ${FORMATTING_BEGIN_BLUE}OPTION${FORMATTING_END}=<value> make ${FORMATTING_BEGIN_YELLOW}<target>${FORMATTING_END}\n"\
} \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " ${FORMATTING_BEGIN_BLUE}%-46s${FORMATTING_END} %s\n", $$1, $$2 } \
/^.?.?##~/ { printf " %-46s${FORMATTING_BEGIN_YELLOW}%-46s${FORMATTING_END}\n", "", substr($$1, 6) } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
GOLANGCI_VERSION = 1.54.2
TRIVY_VERSION= 0.38.3
PROMTOOL_VERSION = 2.37.0
GATOR_VERSION = 3.9.0
GH_VERSION = 2.52.0
TESTS_TIMEOUT="15m"
##@ General
deps: bin/golangci-lint bin/trivy bin/regcopy bin/jq bin/yq bin/crane bin/promtool bin/gator bin/werf bin/gh ## Install dev dependencies.
##@ Tests
bin/promtool-${PROMTOOL_VERSION}/promtool:
mkdir -p bin/promtool-${PROMTOOL_VERSION}
curl -sSfL https://github.com/prometheus/prometheus/releases/download/v${PROMTOOL_VERSION}/prometheus-${PROMTOOL_VERSION}.${GOHOSTOS}-${GOHOSTARCH}.tar.gz -o - | tar zxf - -C bin/promtool-${PROMTOOL_VERSION} --strip=1 prometheus-${PROMTOOL_VERSION}.${GOHOSTOS}-${GOHOSTARCH}/promtool
.PHONY: bin/promtool
bin/promtool: bin/promtool-${PROMTOOL_VERSION}/promtool
rm -f bin/promtool
ln -s promtool-${PROMTOOL_VERSION}/promtool bin/promtool
bin/gator-${GATOR_VERSION}/gator:
mkdir -p bin/gator-${GATOR_VERSION}
curl -sSfL https://github.com/open-policy-agent/gatekeeper/releases/download/v${GATOR_VERSION}/gator-v${GATOR_VERSION}-${GOHOSTOS}-${GOHOSTARCH}.tar.gz -o - | tar zxf - -C bin/gator-${GATOR_VERSION} gator
.PHONY: bin/gator
bin/gator: bin/gator-${GATOR_VERSION}/gator
rm -f bin/gator
ln -s /deckhouse/bin/gator-${GATOR_VERSION}/gator bin/gator
.PHONY: tests-modules tests-matrix tests-openapi tests-controller
tests-modules: ## Run unit tests for modules hooks and templates.
##~ Options: FOCUS=module-name
go test -timeout=${TESTS_TIMEOUT} -vet=off ${TESTS_PATH}
tests-matrix: bin/promtool bin/gator ## Test how helm templates are rendered with different input values generated from values examples.
##~ Options: FOCUS=module-name
go test -timeout=${TESTS_TIMEOUT} ./testing/matrix/ -v
tests-openapi: ## Run tests against modules openapi values schemas.
go test -vet=off ./testing/openapi_cases/
tests-controller: ## Run deckhouse-controller unit tests.
go test ./deckhouse-controller/... -v
.PHONY: validate
validate: ## Check common patterns through all modules.
go test -tags=validation -run Validation -timeout=${TESTS_TIMEOUT} ./testing/...
bin/golangci-lint:
mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}
.PHONY: lint lint-fix
lint: ## Run linter.
golangci-lint run
lint-fix: ## Fix lint violations.
golangci-lint run --fix
.PHONY: --lint-markdown-header lint-markdown lint-markdown-fix
--lint-markdown-header:
@docker pull -q ${MDLINTER_IMAGE}
@echo "\n######################################################################################################################"
@echo '###'
@echo "### Markdown linter report (powered by https://github.com/DavidAnson/markdownlint/)\n"
lint-markdown: --lint-markdown-header ## Run markdown linter.
@bash -c \
"if docker run --rm -v ${PWD}:/workdir ${MDLINTER_IMAGE} --config testing/markdownlint.yaml -p testing/.markdownlintignore '**/*.md' ; then \
echo; echo 'All checks passed.'; \
else \
echo; \
echo 'To run linter locally and fix common problems run: make lint-markdown-fix'; \
echo; \
exit 1; \
fi"
lint-markdown-fix: ## Run markdown linter and fix problems automatically.
@docker run --rm -v ${PWD}:/workdir ${MDLINTER_IMAGE} \
--config testing/markdownlint.yaml -p testing/.markdownlintignore "**/*.md" --fix && (echo 'Fixed successfully.')
##@ Generate
.PHONY: generate render-workflow
generate: bin/werf ## Run all generate-* jobs in bulk.
cd tools; go generate
render-workflow: ## Generate CI workflow instructions.
./.github/render-workflows.sh
##@ Security
bin:
mkdir -p bin
bin/regcopy: bin ## App to copy docker images to the Deckhouse registry
cd tools/regcopy; go build -o bin/regcopy
bin/trivy-${TRIVY_VERSION}/trivy:
mkdir -p bin/trivy-${TRIVY_VERSION}
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b ./bin/trivy-${TRIVY_VERSION} v${TRIVY_VERSION}
.PHONY: trivy
bin/trivy: bin bin/trivy-${TRIVY_VERSION}/trivy
rm -f bin/trivy
ln -s trivy-${TRIVY_VERSION}/trivy bin/trivy
.PHONY: cve-report cve-base-images
cve-report: bin/trivy bin/jq ## Generate CVE report for a Deckhouse release.
##~ Options: SEVERITY=CRITICAL,HIGH REPO=registry.deckhouse.io TAG=v1.30.0
./tools/cve/d8-images.sh
cve-base-images: bin/trivy bin/jq ## Check CVE in our base images.
##~ Options: SEVERITY=CRITICAL,HIGH
./tools/cve/base-images.sh
##@ Documentation
.PHONY: docs
docs: ## Run containers with the documentation.
docker network inspect deckhouse 2>/dev/null 1>/dev/null || docker network create deckhouse
cd docs/documentation/; werf compose up --docker-compose-command-options='-d' --env local --repo ":local"
cd docs/site/; werf compose up --docker-compose-command-options='-d' --env local --repo ":local"
echo "Open http://localhost to access the documentation..."
.PHONY: docs-dev
docs-dev: ## Run containers with the documentation in the dev mode (allow uncommited files).
export WERF_REPO=:local
export SECONDARY_REPO=""
export DOC_API_URL=dev
export DOC_API_KEY=dev
docker network inspect deckhouse 2>/dev/null 1>/dev/null || docker network create deckhouse
cd docs/documentation/; werf compose up --docker-compose-command-options='-d' --dev --env development --repo ":local"
cd docs/site/; werf compose up --docker-compose-command-options='-d' --dev --env development --repo ":local"
echo "Open http://localhost to access the documentation..."
.PHONY: docs-down
docs-down: ## Stop all the documentation containers (e.g. site_site_1 - for Linux, and site-site-1 for MacOs)
docker rm -f site-site-1 site-front-1 site_site_1 site_front_1 documentation 2>/dev/null; docker network rm deckhouse
.PHONY: tests-doc-links
docs-linkscheck: ## Build documentation and run checker of html links.
bash tools/doc_check_links.sh
.PHONY: docs-spellcheck
docs-spellcheck: ## Check the spelling in the documentation.
##~ Options: file="path/to/file" (Specify a path to a specific file)
cd tools/spelling && werf run docs-spell-checker --dev --docker-options="--entrypoint=sh" -- /app/spell_check.sh -f $(file)
lint-doc-spellcheck-pr:
@cd tools/spelling && werf run docs-spell-checker --dev --docker-options="--entrypoint=bash" -- /app/check_diff.sh
.PHONY: docs-spellcheck-generate-dictionary
docs-spellcheck-generate-dictionary: ## Generate a dictionary (run it after adding new words to the tools/spelling/wordlist file).
@echo "Sorting wordlist..."
@sort ./tools/spelling/wordlist -o ./tools/spelling/wordlist
@echo "Generating dictionary..."
@test -f ./tools/spelling/dictionaries/dev_OPS.dic && rm ./tools/spelling/dictionaries/dev_OPS.dic
@touch ./tools/spelling/dictionaries/dev_OPS.dic
@cat ./tools/spelling/wordlist | wc -l | sed 's/^[ \t]*//g' > ./tools/spelling/dictionaries/dev_OPS.dic
@sort ./tools/spelling/wordlist >> ./tools/spelling/dictionaries/dev_OPS.dic
@echo "Don't forget to commit changes and push it!"
@git diff --stat
.PHONY: docs-spellcheck-get-typos-list
docs-spellcheck-get-typos-list: ## Print out a list of all the terms in all pages that were considered as a typo.
@cd tools/spelling && werf run docs-spell-checker --dev --docker-options="--entrypoint=sh" -- "/app/spell_check.sh" 2>/dev/null | sed "1,/Spell-checking the documentation/ d; /^Possible typos/d" | sort -u
##@ Update kubernetes control-plane patchversions
bin/jq-$(JQ_VERSION)/jq:
mkdir -p bin/jq-$(JQ_VERSION)
curl -sSfL https://github.com/stedolan/jq/releases/download/jq-$(JQ_VERSION)/jq-$(JQ_PLATFORM) -o $(PWD)/bin/jq-$(JQ_VERSION)/jq && chmod +x $(PWD)/bin/jq-$(JQ_VERSION)/jq
.PHONY: bin/jq
bin/jq: bin bin/jq-$(JQ_VERSION)/jq ## Install jq deps for update-patchversion script.
rm -f bin/jq
ln -s jq-$(JQ_VERSION)/jq bin/jq
bin/yq: bin ## Install yq deps for update-patchversion script.
curl -sSfL https://github.com/mikefarah/yq/releases/download/v4.25.3/yq_$(YQ_PLATFORM)_$(YQ_ARCH) -o bin/yq && chmod +x bin/yq
bin/crane: bin ## Install crane deps for update-patchversion script.
curl -sSfL https://github.com/google/go-containerregistry/releases/download/v0.10.0/go-containerregistry_$(OS_NAME)_$(CRANE_ARCH).tar.gz | tar -xzf - crane && mv crane bin/crane && chmod +x bin/crane
bin/trdl: bin
curl -sSfL https://tuf.trdl.dev/targets/releases/0.6.3/$(TRDL_PLATFORM)-$(TRDL_ARCH)/bin/trdl -o bin/trdl
chmod +x bin/trdl
bin/werf: bin bin/trdl ## Install werf for images-digests generator.
trdl --home-dir bin/.trdl add werf https://tuf.werf.io 1 b7ff6bcbe598e072a86d595a3621924c8612c7e6dc6a82e919abe89707d7e3f468e616b5635630680dd1e98fc362ae5051728406700e6274c5ed1ad92bea52a2 && \
trdl --home-dir bin/.trdl --no-self-update=true update werf 1.2 stable
ln -sf $$(bin/trdl --home-dir bin/.trdl bin-path werf 1.2 stable | sed 's|^.*/bin/\(.trdl.*\)|\1/werf|') bin/werf
bin/gh: bin ## Install gh cli.
curl -sSfL https://github.com/cli/cli/releases/download/v$(GH_VERSION)/gh_$(GH_VERSION)_$(GH_PLATFORM)_$(GH_ARCH).zip -o bin/gh.zip
unzip -d bin -oj bin/gh.zip gh_$(GH_VERSION)_$(GH_PLATFORM)_$(GH_ARCH)/bin/gh
rm bin/gh.zip
.PHONY: update-k8s-patch-versions
update-k8s-patch-versions: ## Run update-patchversion script to generate new version_map.yml.
cd candi/tools; bash update_kubernetes_patchversions.sh
##@ Lib helm
.PHONY: update-lib-helm
update-lib-helm: ## Update lib-helm.
##~ Options: version=MAJOR.MINOR.PATCH
cd helm_lib/ && yq -i '.dependencies[0].version = "$(version)"' Chart.yaml && helm dependency update && tar -xf charts/deckhouse_lib_helm-*.tgz -C charts/ && rm charts/deckhouse_lib_helm-*.tgz && git add Chart.yaml Chart.lock charts/*
##@ Build
.PHONY: build
set-build-envs:
ifeq ($(WERF_ENV),)
export WERF_ENV=FE
endif
ifeq ($(WERF_CHANNEL),)
export WERF_CHANNEL=ea
endif
ifeq ($(DEV_REGISTRY_PATH),)
export DEV_REGISTRY_PATH=dev-registry.deckhouse.io/sys/deckhouse-oss
endif
ifeq ($(SOURCE_REPO),)
export SOURCE_REPO=https://github.com
endif
ifeq ($(GOPROXY),)
export GOPROXY=https://proxy.golang.org/
endif
ifeq ($(CI_COMMIT_TAG),)
export CI_COMMIT_TAG=$(shell git describe --abbrev=0 2>/dev/null)
endif
ifeq ($(CI_COMMIT_BRANCH),)
export CI_COMMIT_BRANCH=$(shell git branch --show-current)
endif
ifeq ($(CI_COMMIT_REF_NAME),)
export CI_COMMIT_REF_NAME=$(shell git rev-parse --abbrev-ref HEAD)
else
ifeq ($(CI_COMMIT_TAG),)
export CI_COMMIT_REF_NAME=$(CI_COMMIT_BRANCH)
else
export CI_COMMIT_REF_NAME=$(CI_COMMIT_TAG)
endif
endif
ifeq ($(CI_COMMIT_REF_SLUG),)
export CI_COMMIT_REF_SLUG=$(shell bin/gh pr view $$CI_COMMIT_BRANCH --json number -q .number 2>/dev/null)
endif
ifeq ($(DECKHOUSE_REGISTRY_HOST),)
export DECKHOUSE_REGISTRY_HOST=registry.deckhouse.io
endif
ifeq ($(OBSERVABILITY_SOURCE_REPO),)
export OBSERVABILITY_SOURCE_REPO=https://example.com
endif
export WERF_REPO=$(DEV_REGISTRY_PATH)
export REGISTRY_SUFFIX=$(shell echo $(WERF_ENV) | tr '[:upper:]' '[:lower:]')
export SECONDARY_REPO=--secondary-repo $(DECKHOUSE_REGISTRY_HOST)/deckhouse/$(REGISTRY_SUFFIX)
build: set-build-envs ## Build Deckhouse images.
##~ Options: FOCUS=image-name
werf build --parallel=true --parallel-tasks-limit=5 --platform linux/amd64 --save-build-report=true --build-report-path images_tags_werf.json $(SECONDARY_REPO) $(FOCUS)
ifeq ($(FOCUS),)
ifneq ($(CI_COMMIT_REF_SLUG),)
@# By default in the Github CI_COMMIT_REF_SLUG is a 'prNUM' for dev branches.
SRC=$(shell jq -r '.Images."dev".DockerImageName' images_tags_werf.json) && \
DST=$(DEV_REGISTRY_PATH):pr$(CI_COMMIT_REF_SLUG) && \
echo "⚓️ 💫 [$(date -u)] Publish images to dev-registry for branch '$(CI_COMMIT_BRANCH)' and edition '$(WERF_ENV)' using tag '$(CI_COMMIT_REF_SLUG)' ..." && \
echo "⚓️ 💫 [$(date -u)] Publish 'dev' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
SRC=$(shell jq -r '.Images."dev/install".DockerImageName' images_tags_werf.json) && \
DST=$(DEV_REGISTRY_PATH)/install:pr$(CI_COMMIT_REF_SLUG) && \
echo "⚓️ 💫 [$(date -u)] Publish 'dev/install' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
SRC=$(shell jq -r '.Images."dev/install-standalone".DockerImageName' images_tags_werf.json) && \
DST=$(DEV_REGISTRY_PATH)/install-standalone:pr$(CI_COMMIT_REF_SLUG) && \
echo "⚓️ 💫 [$(date -u)] Publish 'dev/install-standalone' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
SRC="$(shell jq -r '.Images."e2e-terraform".DockerImageName' images_tags_werf.json)" && \
DST="$(DEV_REGISTRY_PATH)/e2e-terraform:pr$(CI_COMMIT_REF_SLUG)" && \
echo "⚓️ 💫 [$(date -u)] Publish 'e2e-terraform' image to dev-registry using tag 'pr$(CI_COMMIT_REF_SLUG)'" && \
docker pull $$SRC && \
docker image tag $$SRC $$DST && \
docker image push $$DST && \
docker image rmi $$DST || true
endif
endif
build-render: set-build-envs ## render werf.yaml for build Deckhouse images.
werf config render