forked from KusionStack/kusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
214 lines (167 loc) · 8.48 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
SHELL = /bin/bash
PWD:=$(shell pwd)
KCLVM_BUILDER:=kusionstack/kclvm-builder
RUN_IN_DOCKER:=docker run -it --rm
RUN_IN_DOCKER+=-v ~/.ssh:/root/.ssh
RUN_IN_DOCKER+=-v ~/.gitconfig:/root/.gitconfig
RUN_IN_DOCKER+=-v ~/go/pkg/mod:/go/pkg/mod
RUN_IN_DOCKER+=-v ${PWD}:/root/kusion
RUN_IN_DOCKER+=-w /root/kusion ${KCLVM_BUILDER}
GOFORMATER ?= gofumpt
GOFORMATER_VERSION ?= v0.2.0
GOLINTER ?= golangci-lint
GOLINTER_VERSION ?= v1.56.2
COVER_FILE ?= coverage.out
SOURCE_PATHS ?= ./pkg/...
# TODO: fix mirrors
KCLVM_URL_BASE_MIRRORS:=
.DEFAULT_GOAL := help
CCRED=\033[0;31m
CCEND=\033[0m
# Check if the SKIP_BUILD_PORTAL flag is set to control the portal building process.
# If the flag is not set, the BUILD_PORTAL variable is assigned the value 'build-portal'.
# If the flag is set, the BUILD_PORTAL variable remains empty.
ifndef SKIP_BUILD_PORTAL
BUILD_PORTAL = build-portal
else
BUILD_PORTAL =
endif
# Show the portal build status
show-portal-status:
@if [ "$(BUILD_PORTAL)" = "build-portal" ]; then \
echo "🚀 Building the portal as SKIP_BUILD_PORTAL is not set."; \
echo ""; \
else \
echo "⏭️ Skipping the portal build as SKIP_BUILD_PORTAL is set."; \
echo ""; \
fi
help: ## This help message :)
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# If you encounter an error like "panic: permission denied" on MacOS,
# please visit https://github.com/eisenxp/macos-golink-wrapper to find the solution.
test: ## Run the tests
go test -gcflags="all=-l -N" -timeout=10m `go list $(SOURCE_PATHS)` ${TEST_FLAGS}
cover: ## Generates coverage report
go test -gcflags="all=-l -N" -timeout=10m `go list $(SOURCE_PATHS)` -coverprofile $(COVER_FILE) ${TEST_FLAGS}
cover-html: ## Generates coverage report and displays it in the browser
go tool cover -html=$(COVER_FILE)
format: ## Format source code
@which $(GOFORMATER) > /dev/null || (echo "Installing $(GOFORMATER)@$(GOFORMATER_VERSION) ..."; go install mvdan.cc/gofumpt@$(GOFORMATER_VERSION) && echo -e "Installation complete!\n")
@for path in $(SOURCE_PATHS); do ${GOFORMATER} -l -w -e `echo $${path} | cut -b 3- | rev | cut -b 5- | rev`; done;
lint: ## Lint, will not fix but sets exit code on error
@which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n")
$(GOLINTER) run --deadline=10m $(SOURCE_PATHS)
lint-fix: ## Lint, will try to fix errors and modify code
@which $(GOLINTER) > /dev/null || (echo "Installing $(GOLINTER)@$(GOLINTER_VERSION) ..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLINTER_VERSION) && echo -e "Installation complete!\n")
$(GOLINTER) run --deadline=10m $(SOURCE_PATHS) --fix
doc: ## Start the documentation server with godoc
@which godoc > /dev/null || (echo "Installing godoc@latest ..."; go install golang.org/x/tools/cmd/godoc@latest && echo -e "Installation complete!\n")
godoc -http=:6060
upload: ## Upload kusion bundles to OSS
# 执行前先配置 OSS 环境变量 OSS_ACCESS_KEY_ID OSS_ACCESS_KEY_SECRET
go run ./scripts/oss-upload/main.go
clean: ## Clean build bundles
# Delete old artifacts
-rm -f ./pkg/version/z_update_version.go
-rm -rf ./_build/bundles
build-all: build-local-darwin-all build-local-linux-all build-local-darwin-arm64-all build-local-windows-all ## Build all platforms (darwin, linux, windows)
build-local-darwin: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for macOS
# Delete old artifacts
-rm -f ./pkg/version/z_update_version.go
-rm -rf ./_build/bundles/kusion-darwin
# Update version
go generate ./pkg/version
# Build kusion
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \
go build -o ./_build/bundles/kusion-darwin/bin/kusion \
-ldflags="-s -w" -tags rpc .
build-local-darwin-all: build-local-darwin ## Build kusion for macOS
# Copy docs
cp -r ./docs ./_build/bundles/kusion-darwin/docs
# README.md
cp ./README.md ./_build/bundles/kusion-darwin
# Build tgz
cd ./_build/bundles/kusion-darwin && tar -zcvf ../kusion-darwin.tgz .
cd ./_build/bundles && go run ../../hack/md5file/main.go kusion-darwin.tgz > kusion-darwin.tgz.md5.txt
build-local-darwin-arm64: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for macOS arm64
# Delete old artifacts
-rm -f ./pkg/version/z_update_version.go
-rm -rf ./_build/bundles/kusion-darwin-arm64
mkdir -p ./_build/bundles/kusion-darwin-arm64/bin
mkdir -p ./_build/bundles/kusion-darwin-arm64/kclvm/bin
# Update version
go generate ./pkg/version
# Build kusion
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 \
go build -o ./_build/bundles/kusion-darwin-arm64/bin/kusion \
-ldflags="-s -w" -tags rpc .
build-local-darwin-arm64-all: build-local-darwin-arm64 ## Build kusion for macOS arm64
# Copy docs
cp -r ./docs ./_build/bundles/kusion-darwin-arm64/docs
# README.md
cp ./README.md ./_build/bundles/kusion-darwin-arm64
# Build tgz
cd ./_build/bundles/kusion-darwin-arm64 && tar -zcvf ../kusion-darwin-arm64.tgz .
cd ./_build/bundles && go run ../../hack/md5file/main.go kusion-darwin-arm64.tgz > kusion-darwin-arm64.tgz.md5.txt
build-local-linux-in-docker: ## Build kusionctl-linux in docker
${RUN_IN_DOCKER} make build-local-linux
build-local-linux-all-in-docker: ## Build kusionctl-linux with kcl and kclopenapi in docker
${RUN_IN_DOCKER} make build-local-linux-all
build-local-linux: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for linux
# Delete old artifacts
-rm -f ./pkg/version/z_update_version.go
-rm -rf ./_build/bundles/kusion-linux
mkdir -p ./_build/bundles/kusion-linux/bin
# Update version
go generate ./pkg/version
# Build kusion
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build -o ./_build/bundles/kusion-linux/bin/kusion \
-ldflags="-s -w" -tags rpc .
build-local-linux-all: build-local-linux ## Build kusion for linux
# Copy docs
cp -r ./docs ./_build/bundles/kusion-linux/docs
# Copy README.md
cp ./README.md ./_build/bundles/kusion-linux
# Build tgz
cd ./_build/bundles/kusion-linux && tar -zcvf ../kusion-linux.tgz .
cd ./_build/bundles && go run ../../hack/md5file/main.go kusion-linux.tgz > kusion-linux.tgz.md5.txt
build-local-windows: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for windows
# Delete old artifacts
-rm -f ./pkg/version/z_update_version.go
-rm -rf ./_build/bundles/kusion-windows
mkdir -p ./_build/bundles/kusion-windows/bin
mkdir -p ./_build/bundles/kusion-windows/kclvm/bin
# Update version
go generate ./pkg/version
# Build kusion
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 \
go build -o ./_build/bundles/kusion-windows/bin/kusion.exe \
-ldflags="-s -w" -tags rpc .
build-local-windows-all: build-local-windows ## Build kusion for windows
# Copy docs
cp -r ./docs ./_build/bundles/kusion-windows/docs
# Copy README.md
cp ./README.md ./_build/bundles/kusion-windows
# Build zip
cd ./_build/bundles/kusion-windows && zip -r ../kusion-windows.zip .
cd ./_build/bundles && go run ../../hack/md5file/main.go kusion-windows.zip > kusion-windows.zip.md5.txt
build-portal: ## Build kusion portal
cd ui && npm install && npm run build && touch build/.gitkeep
build-image: ## Build kusion image
docker build -t kusionstack/kusion .
sh-in-docker: ## Run a shell in the docker container of kusion
${RUN_IN_DOCKER} bash
e2e-test:
# Run e2e test
hack/run-e2e.sh $(OSTYPE)
gen-api-spec: ## Generate API Specification with OpenAPI format
@which swag > /dev/null || (echo "Installing [email protected] ..."; go install github.com/swaggo/swag/cmd/[email protected] && echo "Installation complete!\n")
# Generate API documentation with OpenAPI format
-swag init --parseDependency --parseInternal --parseDepth 1 -g ./kusion.go -o api/openapispec/ && echo "🎉 Done!" || (echo "💥 Fail!"; exit 1)
# Format swagger comments
-swag fmt -g pkg/**/*.go && echo "🎉 Done!" || (echo "💥 Failed!"; exit 1)
gen-api-doc: ## Generate API Documentation by API Specification
@which swagger > /dev/null || (echo "Installing [email protected] ..."; go install github.com/go-swagger/go-swagger/cmd/[email protected] && echo "Installation complete!\n")
-swagger generate markdown -f ./api/openapispec/swagger.json --output=docs/api.md && echo "🎉 Done!" || (echo "💥 Fail!"; exit 1)
.PHONY: test cover cover-html format lint lint-fix doc build-changelog upload clean build-all build-image build-local-linux build-local-windows build-local-linux-all build-local-windows-all e2e-test gen-api-spec gen-api-doc build-portal show-portal-status