-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
270 lines (215 loc) · 10.2 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
include Makefile.defs
.PHONY: all
all:
# ----------------
define BUILD_BIN
echo "begin to build bin for $(CMD_BIN_DIR)" ; mkdir -p $(DESTDIR_BIN) ; \
BIN_NAME_LIST=$$( cd $(CMD_BIN_DIR) && ls ) ; \
for BIN_NAME in $${BIN_NAME_LIST} ; do \
rm -f $(DESTDIR_BIN)/$${BIN_NAME} ; \
$(GO_BUILD) -o $(DESTDIR_BIN)/$${BIN_NAME} $(CMD_BIN_DIR)/$${BIN_NAME}/main.go ; \
(($$?!=0)) && echo "error, failed to build $${BIN_NAME}" && exit 1 ; \
echo "succeeded to build $${BIN_NAME} to $(DESTDIR_BIN)/$${BIN_NAME}" ; \
done
endef
.PHONY: build_smartdocter_agent_bin
build_smartdocter_agent_bin: CMD_BIN_DIR:=smartdocter-agent-cmd
build_smartdocter_agent_bin:
@ $(BUILD_BIN)
.PHONY: build_smartdocter_controller_bin
build_smartdocter_controller_bin: CMD_BIN_DIR:=smartdocter-controller-cmd
build_smartdocter_controller_bin:
@ $(BUILD_BIN)
# ==========================
define BUILD_FINAL_IMAGE
echo "Build Image with tag: $(IMAGE_TAG)" ; \
docker buildx build \
--build-arg GIT_COMMIT_VERSION=$(GIT_COMMIT_VERSION) \
--build-arg GIT_COMMIT_TIME=$(GIT_COMMIT_TIME) \
--build-arg VERSION=$(GIT_COMMIT_VERSION) \
--file $(IMAGEDIR)/Dockerfile \
--output type=docker \
--tag ${FINAL_IMAGES}:$(IMAGE_TAG) . ; \
echo "build success for $${i}:$(IMAGE_TAG) "
endef
.PHONY: build_local_image
build_local_image: build_local_smartdocter_agent_image build_local_smartdocter_controller_image
.PHONY: build_local_smartdocter_agent_image
build_local_smartdocter_agent_image: FINAL_IMAGES := $(IMAGE_NAME_AGENT)
build_local_smartdocter_agent_image: IMAGEDIR := $(ROOT_DIR)/images/smartdocter-agent
build_local_smartdocter_agent_image: IMAGE_TAG := $(GIT_COMMIT_VERSION)
build_local_smartdocter_agent_image:
@ $(BUILD_FINAL_IMAGE)
.PHONY: build_local_smartdocter_controller_image
build_local_smartdocter_controller_image: FINAL_IMAGES := $(IMAGE_NAME_CONTROLLER)
build_local_smartdocter_controller_image: IMAGEDIR := $(ROOT_DIR)/images/smartdocter-controller
build_local_smartdocter_controller_image: IMAGE_TAG := $(GIT_COMMIT_VERSION)
build_local_smartdocter_controller_image:
@ $(BUILD_FINAL_IMAGE)
#---------
.PHONY: build_local_base_image
build_local_base_image: build_local_smartdocter_agent_base_image build_local_smartdocter_controller_base_image
define BUILD_BASE_IMAGE
TAG=` git ls-tree --full-tree HEAD -- $(IMAGEDIR) | awk '{ print $$3 }' ` ; \
echo "Build base image with tag: $${TAG}" ; \
docker buildx build \
--build-arg USE_PROXY_SOURCE=true \
--file $(IMAGEDIR)/Dockerfile \
--output type=docker \
--tag $(BASE_IMAGES):$${TAG} $(IMAGEDIR) ; \
(($$?==0)) || { echo "error , failed to build base image" ; exit 1 ;} ; \
echo "build success $(BASE_IMAGES):$${TAG} "
endef
.PHONY: build_local_smartdocter_agent_base_image
build_local_smartdocter_agent_base_image: IMAGEDIR := ./images/smartdocter-agent-base
build_local_smartdocter_agent_base_image: BASE_IMAGES := ${REGISTER}/${GIT_REPO}/smartdocter-agent-base
build_local_smartdocter_agent_base_image:
@ $(BUILD_BASE_IMAGE)
.PHONY: build_local_smartdocter_controller_base_image
build_local_smartdocter_controller_base_image: IMAGEDIR := ./images/smartdocter-controller-base
build_local_smartdocter_controller_base_image: BASE_IMAGES := ${REGISTER}/${GIT_REPO}/smartdocter-controller-base
build_local_smartdocter_controller_base_image:
@ $(BUILD_BASE_IMAGE)
# ==========================
.PHONY: package-charts
package-charts:
@ make -C charts package
.PHONY: lint-golang
lint-golang: LINT_DIR := ./smartdocter-agent-cmd/... ./smartdocter-controller-cmd/...
lint-golang:
$(QUIET) tools/check-go-fmt.sh
$(QUIET) $(GO_VET) $(LINT_DIR)
$(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-markdown-spell
lint-markdown-spell:
if which mdspell &>/dev/null ; then \
mdspell -r --en-us --ignore-numbers --target-relative .github/.spelling --ignore-acronyms '**/*.md' '!vendor/**/*.md' ; \
else \
$(CONTAINER_ENGINE) container run --rm \
--entrypoint bash -v $(ROOT_DIR):/workdir weizhoulan/spellcheck:latest \
-c "cd /workdir ; mdspell -r --en-us --ignore-numbers --target-relative .github/.spelling --ignore-acronyms '**/*.md' '!vendor/**/*.md' " ; \
fi
.PHONY: lint-markdown-spell-colour
lint-markdown-spell-colour:
if which mdspell &>/dev/null ; then \
mdspell -r --en-us --ignore-numbers --target-relative .github/.spelling --ignore-acronyms '**/*.md' '!vendor/**/*.md' ; \
else \
$(CONTAINER_ENGINE) container run --rm -it \
--entrypoint bash -v $(ROOT_DIR):/workdir weizhoulan/spellcheck:latest \
-c "cd /workdir ; mdspell -r --en-us --ignore-numbers --target-relative .github/.spelling --ignore-acronyms '**/*.md' '!vendor/**/*.md' " ; \
fi
.PHONY: lint-code-spell
lint-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
.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: unitest-tests
unitest-tests: UNITEST_DIR := smartdocter-agent-cmd smartdocter-controller-cmd
unitest-tests:
@echo "run unitest-tests"
$(QUIET) $(ROOT_DIR)/tools/ginkgo.sh \
--cover --coverprofile=./coverage.out --covermode set \
--json-report unitestreport.json \
-randomize-suites -randomize-all --keep-going --timeout=1h -p --slow-spec-threshold=120s \
-vv -r $(UNITEST_DIR)
$(QUIET) go tool cover -html=./coverage.out -o coverage-all.html
# 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: e2e
e2e:
@echo "run e2e"
.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 -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 -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: 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)"