-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
198 lines (165 loc) · 6.54 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
# init the build information
ifdef HASTAG
GITTAG=${HASTAG}
else
GITTAG=$(shell git describe --always)
endif
# version
PRO_DIR = $(shell pwd)
BUILDTIME = $(shell date +%Y-%m-%dT%T%z)
GITHASH = $(shell git rev-parse HEAD)
VERSION = $(shell echo ${ENV_BK_BSCP_VERSION})
DEBUG = $(shell echo ${ENV_BK_BSCP_ENABLE_DEBUG})
PREFIX ?= $(shell pwd)
GOBIN = ${PREFIX}/bin/proto
PATH := ${PREFIX}/bin/proto:${PATH}
# protoc v4.22.0
export PROTOC_VERSION=25.1
GOBUILD=CGO_ENABLED=0 go build -trimpath
# output directory for release package and version for command line
ifeq ("$(VERSION)", "")
export OUTPUT_DIR = ${PRO_DIR}/build/bk-bscp
export LDVersionFLAG = "-X github.com/TencentBlueKing/bk-bscp/pkg/version.BUILDTIME=${BUILDTIME} \
-X github.com/TencentBlueKing/bk-bscp/pkg/version.GITHASH=${GITHASH} \
-X github.com/TencentBlueKing/bk-bscp/pkg/version.GITTAG=${GITTAG} \
-X github.com/TencentBlueKing/bk-bscp/pkg/version.DEBUG=${DEBUG}"
else
export OUTPUT_DIR = ${PRO_DIR}/build/bk-bscp-${VERSION}
export LDVersionFLAG = "-X github.com/TencentBlueKing/bk-bscp/pkg/version.VERSION=${VERSION} \
-X github.com/TencentBlueKing/bk-bscp/pkg/version.BUILDTIME=${BUILDTIME} \
-X github.com/TencentBlueKing/bk-bscp/pkg/version.GITHASH=${GITHASH} \
-X github.com/TencentBlueKing/bk-bscp/pkg/version.DEBUG=${DEBUG}"
endif
include ./scripts/makefile/uname.mk
default: all
.PHONY: init
init:
@echo Download protoc
@mkdir -p ${PREFIX}/bin/proto
@cd ${PREFIX}/bin/proto && \
rm -rf protoc-*.zip* && \
wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \
unzip -o protoc-${PROTOC_VERSION}-linux-x86_64.zip && \
mv -f bin/protoc . && \
rm -rf protoc-*.zip* readme.txt bin include
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
go install github.com/grpc-ecosystem/grpc-gateway/v2/[email protected]
go install github.com/ifooth/grpc-gateway/v2/[email protected]
@echo Download gotext
go install golang.org/x/text/cmd/[email protected]
.PHONY: tidy
tidy:
go mod tidy -compat=1.17
pre:
@echo -e "\e[34;1mBuilding...\n\033[0m"
mkdir -p ${OUTPUT_DIR}
install: pre
@echo -e "\e[34;1mPackaging Install Tools...\033[0m"
mkdir -p ${OUTPUT_DIR}/install/
@cp -rf ${PRO_DIR}/scripts/install/start_all.sh ${OUTPUT_DIR}/install/
@cp -rf ${PRO_DIR}/scripts/install/stop_all.sh ${OUTPUT_DIR}/install/
@echo -e "\e[34;1mPackaging Install Tools Done\n\033[0m"
api: pre
@echo -e "\e[34;1mPackaging API Docs...\033[0m"
@mkdir -p ${OUTPUT_DIR}/api/
@mkdir -p ${OUTPUT_DIR}/api/api-server
@cp -f api/api-docs/api-server/api/bk_apigw_resources.yml ${OUTPUT_DIR}/api/api-server
@tar -czf ${OUTPUT_DIR}/api/api-server/zh.tgz -C api/api-docs/api-server/docs zh
@mkdir -p ${OUTPUT_DIR}/api/feed-server
@cp -f api/api-docs/feed-server/api/bk_apigw_resources.yml ${OUTPUT_DIR}/api/feed-server
@tar -czf ${OUTPUT_DIR}/api/feed-server/zh.tgz -C api/api-docs/feed-server/docs zh
@echo -e "\e[34;1mPackaging API Docs Done\n\033[0m"
pb:
@echo -e "\e[34;1mFormat proto...\033[0m"
@find pkg/protocol -type f -name "*.proto"|xargs clang-format -i --style="{BasedOnStyle: Google, ColumnLimit: 120}"
@echo -e "\e[34;1mMake Protocol...\033[0m"
@cd pkg/protocol && make clean && make
@echo -e "\e[34;1mMake Protocol Done\n\033[0m"
docs: api_docs bkapigw_docs
api_docs:
@mkdir -p ${PREFIX}/docs/swagger
@protoc --proto_path=. --proto_path=internal/thirdparty/protobuf/ \
--openapiv2_out docs/swagger \
--openapiv2_opt allow_merge=true \
--openapiv2_opt preserve_rpc_order=true \
--openapiv2_opt merge_file_name=api \
--openapiv2_opt output_format=json \
--openapiv2_opt include_without_visibility=true \
--openapiv2_opt visibility_restriction_selectors=BKAPIGW \
--openapiv2_opt use_go_templates=true pkg/protocol/config-server/*.proto
bkapigw_docs:
@mkdir -p ${PREFIX}/docs/swagger
@protoc --proto_path=. --proto_path=internal/thirdparty/protobuf/ \
--openapiv2_out docs/swagger \
--openapiv2_opt allow_merge=true \
--openapiv2_opt preserve_rpc_order=true \
--openapiv2_opt merge_file_name=bkapigw \
--openapiv2_opt output_format=json \
--openapiv2_opt include_without_visibility=false \
--openapiv2_opt visibility_restriction_selectors=BKAPIGW \
--openapiv2_opt use_go_templates=true pkg/protocol/config-server/*.proto
.PHONY: gen
gen:
@go run scripts/gen/main.go
.PHONY: lint
lint:
@golangci-lint run --issues-exit-code=0 --fix --skip-dirs=test --skip-dirs=pkg/logs/glog
test: pre
@cd test/suite && make && cp -rf suite-test ${OUTPUT_DIR}/ && rm -rf suite-test
@cd test/benchmark && make && cp -rf bench-test ${OUTPUT_DIR}/ && rm -rf bench-test
unit-test: pre
@echo -e "\e[34;1mExec Unit Test...\033[0m"
@mkdir -p ${OUTPUT_DIR}/unit-test
@cd cmd/sidecar/scheduler && go test -o ${OUTPUT_DIR}/unit-test/scheduler.test -c
@echo -e "\e[34;1mExec Unit Test Success\n\033[0m"
mock: pre
@cd ${PRO_DIR}/test/mock/repo && make
all: pre validate pb install test unit-test api mock build_bscp
@echo -e "\e[34;1mBuild All Success!\n\033[0m"
server: validate api
@echo -e "\e[34;1mMaking Server...\n\033[0m"
@echo "version: ${VERSION}" > ${OUTPUT_DIR}/VERSION
@cp -rf ${PRO_DIR}/server-CHANGELOG.md ${OUTPUT_DIR}
@mkdir -p ${OUTPUT_DIR}/install/
@mkdir -p ${OUTPUT_DIR}
@mkdir -p ${OUTPUT_DIR}/etc
@cd ${PRO_DIR}/cmd && make server
@echo -e "\e[34;1mMake Server All Success!\n\033[0m"
sidecar: pre validate
@echo -e "\e[34;1mMaking Sidecar...\n\033[0m"
@echo "version: ${VERSION}" > ${OUTPUT_DIR}/VERSION
@cp -rf ${PRO_DIR}/sidecar-CHANGELOG.md ${OUTPUT_DIR}
@cd ${PRO_DIR}/cmd/sidecar && make
@echo -e "\e[34;1mMake Sidecar Success!\n\033[0m"
validate:
@if [ "$(VERSION)" != "" ];then \
if [[ "$(VERSION)" =~ ^(v[0-9]+.[0-9]+.[0-9]+){1}(-alpha[0-9]+)? ]];then \
echo "version: "$(VERSION); \
else \
exit 1; \
fi \
fi
clean:
@cd ${PRO_DIR}/cmd && make clean
@rm -rf ${PRO_DIR}/build
.PHONY: openapi
openapi:
@swag init --outputTypes go,json -g pkg/web/web.go --exclude ./
@swag fmt -g pkg/web/web.go --exclude ./
.PHONY: build_bscp
build_bscp:
@cd ${PRO_DIR}/cmd && make all
.PHONY: build_feed
build_feed:
@cd ${PRO_DIR}/cmd && make feed
.PHONY: build_frontend
build_frontend:
cd ui; npm install --legacy-peer-deps; npm run build
.PHONY: docker
docker:
@docker build -t bk-bscp-hyper:latest .
.PHONY: i18n
i18n:
@go generate ./internal/i18n/translations/translations.go
@cp ./internal/i18n/translations/locales/zh/out.gotext.json ./internal/i18n/translations/locales/zh/messages.gotext.json