-
Notifications
You must be signed in to change notification settings - Fork 201
/
package.sh
executable file
·276 lines (255 loc) · 8.34 KB
/
package.sh
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
#!/bin/bash
set -e
echo 'Begin to package job'
BACKEND_MODULES=(job-config job-crontab job-execute job-gateway job-logsvr job-manage job-backup job-file-gateway job-file-worker job-analysis job-assemble)
FRONTEND_MODULES=(job-frontend)
ALL_MODULES=(job-config job-crontab job-execute job-gateway job-logsvr job-manage job-backup job-file-gateway job-file-worker job-analysis job-frontend job-assemble)
JOB_EDITION=ce
if [[ ! -d "release" ]]; then
mkdir release
else
rm -rf release/*
fi
usage () {
cat <<EOF
用法:
$PROGRAM [ -h --help -? 查看帮助 ]
[ -m, --module [必选] "子模块(${PROJECTS[*]}), 逗号分隔。ALL表示全部模块" ]
[ -v, --version [必选] "Job版本" ]
[ -e, --edition [非必选] "Job出包类型,ce表示社区版,ee表示企业版,默认ce" ]
EOF
}
usage_and_exit () {
usage
exit "$1"
}
log () {
echo "$@"
}
error () {
echo "$@" 1>&2
usage_and_exit 1
}
warning () {
echo "$@" 1>&2
EXITCODE=$((EXITCODE + 1))
}
# 解析命令行参数,长短混合模式
(( $# == 0 )) && usage_and_exit 1
while (( $# > 0 )); do
case "$1" in
-m | --module )
shift
JOB_MODULES="$1"
;;
-v | --version )
shift
JOB_VERSION="$1"
;;
-e | --edition )
shift
JOB_EDITION="$1"
;;
--help | -h | '-?' )
usage_and_exit 0
;;
-*)
error "不可识别的参数: $1"
;;
*)
break
;;
esac
shift
done
echo ${JOB_MODULES}
JOB_MODULES=${JOB_MODULES,,} # to lower case
# 判断参数
if [[ -z $JOB_MODULES ]] || ! [[ $JOB_MODULES =~ ^[A-Za-z,-]+$ ]]; then
warning "-m, --module必须指定要更新的模块名, 逗号分隔: 如job-config,job-logsvr"
fi
# 解析需要更新的模块,如果是all/ALL,则包含所有模块
if [[ $JOB_MODULES = all ]]; then
PACKAGE_MODULES=("${ALL_MODULES[@]}")
else
IFS=, read -ra PACKAGE_MODULES <<<"$JOB_MODULES"
fi
function packageJarAndScript()
{
backend_module="$1"
log "current dir:$(pwd)"
ls
log "Packaging $backend_module ..."
if [[ ! -d "release" ]]; then
mkdir release
fi
mkdir -p release/job/backend/${backend_module}/bin
cp src/backend/release/${backend_module}-${JOB_VERSION}.jar release/job/backend/${backend_module}/${backend_module}.jar
cp scripts/${backend_module}/${backend_module}.sh release/job/backend/${backend_module}/bin/
chmod 755 release/job/backend/${backend_module}/bin/${backend_module}.sh
echo "Package ${backend_module} successfully"
}
# Package the back-end jar file and the corresponding execution script
for m in "${PACKAGE_MODULES[@]}"; do
for BACKEND_MODULE in ${BACKEND_MODULES[@]}
do
[ "$BACKEND_MODULE" == "$m" ] && packageJarAndScript $m
done
# Package Upgrader
if [[ ! -d "release/job/backend" ]]; then
mkdir -p release/job/backend
fi
if [[ -f "src/backend/release/upgrader-${JOB_VERSION}.jar" ]]; then
cp src/backend/release/upgrader-${JOB_VERSION}.jar release/job/backend/upgrader-${JOB_VERSION}.jar
fi
done
# Package versionLogs
if [ ! -d "src/frontend/release/job/frontend/static" ]
then
mkdir -p src/frontend/release/job/frontend/static
fi
if [ ! -d "release/job/frontend/static" ]
then
mkdir -p release/job/frontend/static
fi
cp versionLogs/bundledVersionLog*.json release/job/frontend/static
if [ ! -d "src/frontend/dist/*" ]
then
mkdir -p src/frontend/dist/_init_
fi
# Package front-end static files
for m in "${PACKAGE_MODULES[@]}"; do
for FRONTEND_MODULE in ${FRONTEND_MODULES[@]}
do
if [[ "$FRONTEND_MODULE" == "$m" ]]; then
log "Packaging $m ..."
mkdir -p release/job/frontend
cp -r src/frontend/dist/* release/job/frontend/
echo "Package frontend successfully"
fi
done
done
# Package support-files
log "Packaging support-files ..."
if [[ ! -d "release/job/support-files" ]]; then
mkdir -p release/job/support-files
fi
cp -r support-files/bk-cmdb/ release/job/support-files/
cp -r support-files/bkiam/ release/job/support-files/
cp -r support-files/dependJarInfo/ release/job/support-files/
# Package dependJarLists
if [[ -d "support-files/dependJarLists/" ]]; then
cp -r support-files/dependJarLists/ release/job/support-files/
fi
# Package SQL by modules
if [[ ! -d "release/job/support-files/sql" ]]; then
mkdir -p release/job/support-files/sql
fi
for m in "${PACKAGE_MODULES[@]}"; do
if [[ -d "support-files/sql/${m}" ]]; then
cp -r "support-files/sql/${m}/" release/job/support-files/sql/
fi
done
# Package Templates by modules
cd support-files/tools
export PYTHONIOENCODING=utf8
python renderTemplates.py ${JOB_EDITION} w
cd ../..
if [[ -d "support-files/templates" ]]; then
if [[ ! -d "release/job/support-files/templates" ]]; then
mkdir -p release/job/support-files/templates
fi
for m in "${PACKAGE_MODULES[@]}"; do
if [[ "job-frontend" == "${m}" ]]; then
continue
fi
simpleName=${m:4}
# job-assemble 配置文件单独处理
if [[ "${m}" == "job-assemble" ]]; then
moduleConfigFilePath="support-files/templates/#etc#job#job-${simpleName}#application-${simpleName}.yml"
if [[ -f "${moduleConfigFilePath}" ]]; then
cp "${moduleConfigFilePath}" release/job/support-files/templates
else
echo "cannot find yml template of #etc#job#job-assemble#application-assemble.yml"
exit 1
fi
moduleConfigFilePath="support-files/templates/#etc#job#job-assemble#application-gateway.yml"
if [[ -f "${moduleConfigFilePath}" ]]; then
cp "${moduleConfigFilePath}" release/job/support-files/templates
else
echo "cannot find yml template of #etc#job#job-assemble#application-gateway.yml"
exit 1
fi
continue
fi
# Copy yml templates
moduleConfigFilePath="support-files/templates/#etc#job#job-${simpleName}#job-${simpleName}.yml"
if [[ -f "${moduleConfigFilePath}" ]]; then
cp "${moduleConfigFilePath}" release/job/support-files/templates
else
if [[ "${simpleName}" != "config" && "${simpleName}" != "file-worker" ]];then
echo "cannot find yml template of job-${simpleName}"
exit 1
fi
fi
# Copy application-{module}.yml templates
moduleConfigFilePath="support-files/templates/#etc#job#application-${simpleName}.yml"
if [[ -f "${moduleConfigFilePath}" ]]; then
cp "${moduleConfigFilePath}" release/job/support-files/templates
else
if [[ "${simpleName}" != "file-worker" ]];then
echo "cannot find yml template of application-${simpleName}"
exit 1
fi
fi
done
# Copy job-common.yml
simpleName='common'
propertiesFilePath="support-files/templates/#etc#job#job-${simpleName}#*"
cp ${propertiesFilePath} release/job/support-files/templates
# Copy upgrader.properties
upgraderPropertiesFile="support-files/templates/#etc#job#upgrader#upgrader.properties"
if [[ -f "${upgraderPropertiesFile}" ]]; then
cp "${upgraderPropertiesFile}" release/job/support-files/templates
else
echo "warn: cannot find ${upgraderPropertiesFile}, ignore"
fi
# Copy job.env
jobEnvFile="support-files/templates/job.env"
if [[ -f "${jobEnvFile}" ]]; then
cp "${jobEnvFile}" release/job/support-files/templates
else
echo "warn: cannot find ${jobEnvFile}, ignore"
fi
# Copy deploy.yml/deploy_assemble.yml
cp "support-files/templates/#job#deploy.yml" release/job/support-files/templates
cp "support-files/templates/#job#deploy_lite.yml" release/job/support-files/templates
fi
# readme.md、requirements.txt
for fileName in "readme.md" "requirements.txt";
do
filePath="support-files/${fileName}"
if [[ -f "${filePath}" ]]; then
cp "${filePath}" release/job/support-files/
fi
done
echo "Package support-files successfully"
# Package project documents
log "Packaging project doc ..."
cp README.md release/job/
cp projects.yaml release/job/
cp release.md release/job/
cp UPGRADE.md release/job/
cp VERSION release/job/
cp -r docs/ release/job/
echo "Package project doc successfully"
cd release
# 企业版、社区版包名称差异处理
if [[ "${JOB_EDITION}" == "ee" ]];then
tar -czf "job_ee-${JOB_VERSION}.tgz" job
log "Package job successfully! File: job_ee-${JOB_VERSION}.tgz"
else
tar -czf "job_ce-${JOB_VERSION}.tgz" job
log "Package job successfully! File: job_ce-${JOB_VERSION}.tgz"
fi
set +e