-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
302 lines (248 loc) · 11.1 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
#!/usr/bin/make -f
# Copyright 2022 Authors of kmerge
# SPDX-License-Identifier: Apache-2.0
include Makefile.defs
all: build-bin install-bin clean-bin
.PHONY: all build install clean-bin
CONTROLLER_BIN_SUBDIRS := cmd/daemon
SUBDIRS := $(CONTROLLER_BIN_SUBDIRS)
build-bin:
for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i all; done
clean-bin:
$(QUIET) for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i clean; done
install-bin:
$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR_BIN)
for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i install; done
install-bash-completion:
$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR_BIN)
for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i install-bash-completion; done
# ============ build-load-image ============
.PHONY: image
image:
@for NAME in $(IMAGES); do \
docker build --build-arg RACE --build-arg GIT_COMMIT_VERSION=$(GIT_COMMIT_VERSION) \
--build-arg GIT_COMMIT_TIME=$(GIT_COMMIT_TIME) \
--build-arg VERSION=$(GIT_COMMIT_VERSION) \
--file $(ROOT_DIR)/images/"$${NAME##*/}"/Dockerfile \
--output type=docker --tag $${NAME}:$(IMAGE_TAG) . ; \
echo "Image $${NAME##*/} build success" ; \
done
.PHONY: lint-golang
lint-golang:
@$(ECHO_CHECK) contrib/scripts/check-go-fmt.sh
$(QUIET) contrib/scripts/check-go-fmt.sh
@$(ECHO_CHECK) vetting all GOFILES...
$(QUIET) $(GO_VET) \
./cmd/... \
./pkg/... \
./contrib/...
@$(ECHO_CHECK) golangci-lint
$(QUIET) golangci-lint run
.PHONY: lint-markdown-format
lint-markdown-format:
@$(CONTAINER_ENGINE) container run --rm \
--entrypoint sh -v $(ROOT_DIR):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest \
-c '/usr/local/bin/markdownlint -c /workdir/.github/markdownlint.yaml -p /workdir/.github/markdownlintignore /workdir/' ; \
if (($$?==0)) ; then echo "congratulations ,all pass" ; else echo "error, pealse refer <https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md> " ; fi
.PHONY: fix-markdown-format
fix-markdown-format:
@$(CONTAINER_ENGINE) container run --rm \
--entrypoint sh -v $(ROOT_DIR):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest \
-c '/usr/local/bin/markdownlint -f -c /workdir/.github/markdownlint.yaml -p /workdir/.github/markdownlintignore /workdir/'
.PHONY: lint-yaml
lint-yaml:
@$(CONTAINER_ENGINE) container run --rm \
--entrypoint sh -v $(ROOT_DIR):/data cytopia/yamllint \
-c '/usr/bin/yamllint -c /data/.github/yamllint-conf.yml /data' ; \
if (($$?==0)) ; then echo "congratulations ,all pass" ; else echo "error, pealse refer <https://yamllint.readthedocs.io/en/stable/rules.html> " ; fi
.PHONY: lint-code-spell
lint-code-spell:
$(QUIET) if ! which codespell &> /dev/null ; then \
echo "try to install codespell" ; \
if ! pip3 install codespell==2.2.1 ; then \
echo "error, miss tool codespell, install it: pip3 install codespell" ; \
exit 1 ; \
fi \
fi ;\
codespell --config .github/codespell-config
.PHONY: fix-code-spell
fix-code-spell:
$(QUIET) if ! which codespell &> /dev/null ; then \
echo "try to install codespell" ; \
if ! pip3 install codespell ; then \
echo "error, miss tool codespell, install it: pip3 install codespell" ; \
exit 1 ;\
fi \
fi; \
codespell --config .github/codespell-config --write-changes
.PHONY: gofmt
gofmt: ## Run gofmt on Go source files in the repository.
$(QUIET)for pkg in $(GOFILES); do $(GO) fmt $$pkg; done
.PHONY: dev-doctor
dev-doctor:
@ $(GO) version 2>/dev/null || ( echo "go not found, see https://golang.org/doc/install" ; false )
@ JUST_CLI_CHECK=true test/scripts/install-tools.sh
@ echo "all tools ready"
#============ tools ====================
.PHONY: update-authors
update-authors: ## Update AUTHORS file for the repository.
@echo "Updating AUTHORS file..."
@echo "The following people, in alphabetical order, have either authored or signed" > AUTHORS
@echo "off on commits in the kmerge repository:" >> AUTHORS
@echo "" >> AUTHORS
@contrib/authorgen/authorgen.sh >> AUTHORS
.PHONY: licenses-all
licenses-all: ## Generate file with all the License from dependencies.
@$(GO) run ./contrib/licensegen > LICENSE.all || ( rm -f LICENSE.all ; false )
.PHONY: licenses-check
licenses-check:
@$(ECHO_CHECK) tools/scripts/check-miss-license.sh
$(QUIET) tools/scripts/check-miss-license.sh
.PHONY: update-go-version
update-go-version: ## Update Go version for all the components
@echo "GO_MAJOR_AND_MINOR_VERSION=${GO_MAJOR_AND_MINOR_VERSION}"
@echo "GO_IMAGE_VERSION=${GO_IMAGE_VERSION}"
# ===== Update Go version for GitHub workflow
$(QUIET) for fl in $(shell find .github/workflows -name "*.yaml" -print) ; do \
sed -i 's/go-version: .*/go-version: ${GO_IMAGE_VERSION}/g' $$fl ; \
done
@echo "Updated go version in GitHub Actions to $(GO_IMAGE_VERSION)"
# ======= Update Go version in main.go.
$(QUIET) for fl in $(shell find . -name main.go -not -path "./vendor/*" -print); do \
sed -i \
-e 's|^//go:build go.*|//go:build go${GO_MAJOR_AND_MINOR_VERSION}|g' \
-e 's|^// +build go.*|// +build go${GO_MAJOR_AND_MINOR_VERSION}|g' \
$$fl ; \
done
# ====== Update Go version in go.mod
$(QUIET) sed -i -E 's/^go .*/go '$(GO_MAJOR_AND_MINOR_VERSION)'/g' go.mod
@echo "Updated go version in go.mod to $(GO_VERSION)"
ifeq (${shell [ -d ./test ] && echo done},done)
# ======= Update Go version in test scripts.
@echo "Updated go version in test scripts to $(GO_VERSION)"
endif
# ===== Update Go version in Dockerfiles.
$(QUIET) $(MAKE) -C images update-golang-image
@echo "Updated go version in image Dockerfiles to $(GO_IMAGE_VERSION)"
# ==========================
# should label for each test file
.PHONY: check_test_label
check_test_label:
@ALL_TEST_FILE=` find ./ -name "*_test.go" -not -path "./vendor/*" ` ; FAIL="false" ; \
for ITEM in $$ALL_TEST_FILE ; do \
[[ "$$ITEM" == *_suite_test.go ]] && continue ; \
! grep 'Label(' $${ITEM} &>/dev/null && FAIL="true" && echo "error, miss Label in $${ITEM}" ; \
done ; \
[ "$$FAIL" == "true" ] && echo "error, label check fail" && exit 1 ; \
echo "each test.go is labeled right"
.PHONY: unitest-tests
unitest-tests: check_test_label
@echo "run unitest-tests"
$(QUIET) $(ROOT_DIR)/tools/scripts/ginkgo.sh \
--cover --coverprofile=./coverage.out --covermode set \
--json-report unitestreport.json \
-randomize-suites -randomize-all --keep-going --timeout=1h -p \
-vv -r $(ROOT_DIR)/pkg $(ROOT_DIR)/cmd
$(QUIET) go tool cover -html=./coverage.out -o coverage-all.html
.PHONY: preview_doc
preview_doc: PROJECT_DOC_DIR := ${ROOT_DIR}/docs
preview_doc:
-docker stop doc_previewer &>/dev/null
-docker rm doc_previewer &>/dev/null
@echo "set up preview http server "
@echo "you can visit the website on browser with url 'http://127.0.0.1:8000' "
[ -f "docs/mkdocs.yml" ] || { echo "error, miss docs/mkdocs.yml "; exit 1 ; }
docker run --rm -p 8000:8000 --name doc_previewer -v $(PROJECT_DOC_DIR):/host/docs \
--entrypoint sh \
--stop-timeout 3 \
--stop-signal "SIGKILL" \
squidfunk/mkdocs-material:8.5.11 -c "cd /host ; cp docs/mkdocs.yml ./ ; mkdocs serve -a 0.0.0.0:8000"
#sleep 10 ; if curl 127.0.0.1:8000 &>/dev/null ; then echo "succeeded to set up preview server" ; else echo "error, failed to set up preview server" ; docker stop doc_previewer ; exit 1 ; fi
.PHONY: build_doc
build_doc: PROJECT_DOC_DIR := ${ROOT_DIR}/docs
build_doc: OUTPUT_TAR := site.tar.gz
build_doc:
-docker stop doc_builder &>/dev/null
-docker rm doc_builder &>/dev/null
[ -f "docs/mkdocs.yml" ] || { echo "error, miss docs/mkdocs.yml "; exit 1 ; }
-@ rm -f ./docs/$(OUTPUT_TAR)
@echo "build doc html " ; \
docker run --rm --name doc_builder \
-v ${PROJECT_DOC_DIR}:/host/docs \
--entrypoint sh \
squidfunk/mkdocs-material:8.5.11 -c "cd /host && cp ./docs/mkdocs.yml ./ && mkdocs build && cd site && tar -czvf site.tar.gz * && mv ${OUTPUT_TAR} ../docs/"
@ [ -f "$(PROJECT_DOC_DIR)/$(OUTPUT_TAR)" ] || { echo "failed to build site to $(PROJECT_DOC_DIR)/$(OUTPUT_TAR) " ; exit 1 ; }
@ echo "succeeded to build site to $(PROJECT_DOC_DIR)/$(OUTPUT_TAR) "
.PHONY: check_doc
check_doc: PROJECT_DOC_DIR := ${ROOT_DIR}/docs
check_doc: OUTPUT_TAR := site.tar.gz
check_doc:
-docker stop doc_builder &>/dev/null
-docker rm doc_builder &>/dev/null
[ -f "docs/mkdocs.yml" ] || { echo "error, miss docs/mkdocs.yml "; exit 1 ; }
-@ rm -f ./docs/$(OUTPUT_TAR)
@echo "check doc" ; \
MESSAGE=`docker run --rm --name doc_builder \
-v ${PROJECT_DOC_DIR}:/host/docs \
--entrypoint sh \
squidfunk/mkdocs-material:8.5.11 -c "cd /host && cp ./docs/mkdocs.yml ./ && mkdocs build 2>&1 && cd site && tar -czvf site.tar.gz * && mv ${OUTPUT_TAR} ../docs/" 2>&1` ; \
if (( $$? !=0 )) ; then \
echo "!!! error, failed to build doc" ; \
exit 1 ; \
fi ; \
if grep -E "WARNING .* which is not found" <<< "$${MESSAGE}" ; then \
echo "!!! error, some link is bad" ; \
exit 1 ; \
fi
@ [ -f "$(PROJECT_DOC_DIR)/$(OUTPUT_TAR)" ] || { echo "failed to build site to $(PROJECT_DOC_DIR)/$(OUTPUT_TAR) " ; exit 1 ; }
-@ rm -f ./docs/$(OUTPUT_TAR)
@ echo "all doc is ok "
# ==========================
.PHONY: clean_e2e
clean_e2e:
-$(QUIET) make -C test clean
-$(QUIET) rm -f e2ereport.json
.PHONY: clean
clean: clean_e2e
-$(QUIET) for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i clean; done
-$(QUIET) rm -rf $(DESTDIR_BIN)
-$(QUIET) rm -rf $(DESTDIR_BASH_COMPLETION)
.PHONY: codegen
codegen:
@echo "Generate k8s SDK with code-generator."
$(QUIET) ./tools/scripts/update-codegen.sh
.PHONY: codegen-verify
codegen-verify:
@echo "Verify generated k8s SDK."
$(QUIET) ./tools/scripts/verify-codegen.sh
.PHONY: lint_image_trivy
lint_image_trivy: IMAGE_NAME ?=
lint_image_trivy:
@ [ -n "$(IMAGE_NAME)" ] || { echo "error, please input IMAGE_NAME" && exit 1 ; }
@ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
-v $(ROOT_DIR)/.trivyignore:/.trivyignore \
-v /tmp/trivy:/root/trivy.cache/ \
aquasec/trivy:$(TRIVY_VERSION) image --exit-code 1 --severity $(LINT_TRIVY_SEVERITY_LEVEL) $(IMAGE_NAME) ; \
(($$?==0)) || { echo "error, failed to check dockerfile trivy", $(IMAGE_NAME) && exit 1 ; } ; \
echo "trivy check: $(IMAGE_NAME) pass"
.PHONY: lint_dockerfile_trivy
lint_dockerfile_trivy:
@ docker run --rm \
-v $(ROOT_DIR)/.trivyignore:/.trivyignore \
-v /tmp/trivy:/root/trivy.cache/ \
-v $(ROOT_DIR):/tmp/src \
aquasec/trivy:$(TRIVY_VERSION) config --exit-code 1 --severity $(LINT_TRIVY_SEVERITY_LEVEL) /tmp/src/images ; \
(($$?==0)) || { echo "error, failed to check dockerfile trivy" && exit 1 ; } ; \
echo "dockerfile trivy check: pass"
.PHONY: lint_chart_trivy
lint_chart_trivy:
@ docker run --rm \
-v $(ROOT_DIR)/.trivyignore:/.trivyignore \
-v /tmp/trivy:/root/trivy.cache/ \
-v $(ROOT_DIR):/tmp/src \
aquasec/trivy:$(TRIVY_VERSION) config --exit-code 1 --severity $(LINT_TRIVY_SEVERITY_LEVEL) /tmp/src/charts ; \
(($$?==0)) || { echo "error, failed to check chart trivy" && exit 1 ; } ; \
echo "chart trivy check: pass"
.PHONY: build-chart
build-chart:
@ cd charts ; make