forked from deckhouse/deckhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
246 lines (195 loc) · 10.6 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
export PATH := $(abspath bin/):${PATH}
FORMATTING_BEGIN_YELLOW = \033[0;33m
FORMATTING_BEGIN_BLUE = \033[36m
FORMATTING_END = \033[0m
TESTS_TIMEOUT="15m"
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
else ifeq ($(OS_NAME), Darwin)
JQ_PLATFORM = osx-amd64
YQ_PLATFORM = darwin
TRDL_PLATFORM = darwin
endif
JQ_VERSION = 1.6
# Set arch for deps
ifeq ($(PLATFORM_NAME), x86_64)
YQ_ARCH = amd64
CRANE_ARCH = x86_64
TRDL_ARCH = amd64
else ifeq ($(PLATFORM_NAME), arm64)
YQ_ARCH = arm64
CRANE_ARCH = arm64
TRDL_ARCH = arm64
endif
# Set arch for crane
ifeq ($(PLATFORM_NAME), x86_64)
CRANE_ARCH = x86_64
else ifeq ($(PLATFORM_NAME), arm64)
CRANE_ARCH = arm64
endif
# Set testing path for tests-modules
ifeq ($(FOCUS),"")
TESTS_PATH = ./modules/... ./global-hooks/... ./ee/modules/... ./ee/fe/modules/...
else
TESTS_PATH = $(wildcard ./modules/*-${FOCUS} ./ee/modules/*-${FOCUS} ./ee/fe/modules/*-${FOCUS})/...
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.46.2
TRIVY_VERSION= 0.28.1
PROMTOOL_VERSION = 2.37.0
GATOR_VERSION = 3.9.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 ## 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-prometheus
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 ./testing/matrix/ -v
tests-openapi: ## Run tests against modules openapi values schemas.
go test -vet=off ./testing/openapi_cases/
.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/release.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 (werf is required to build the containers).
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
cd docs/site/; werf compose up --docker-compose-command-options='-d' --env 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).
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
cd docs/site/; werf compose up --docker-compose-command-options='-d' --dev --env development
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
##@ 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-tags 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
.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