forked from didi/KnowStreaming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
91 lines (75 loc) · 2.43 KB
/
build.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
#!/bin/bash
workspace=$(cd $(dirname $0) && pwd -P)
cd $workspace
## constant
app_name=kafka-manager
output_dir=output
gitversion=.gitversion
control=./control.sh
create_mysql_table=./docs/install_guide/create_mysql_table.sql
app_config_file=./kafka-manager-web/src/main/resources/application.yml
## function
function build() {
# 进行编译
# # cmd 设置使用的JDK, 按需选择, 默认已安装了JDK 8
# JVERSION=`java -version 2>&1 | awk 'NR==1{gsub(/"/,"");print $3}'`
# major=`echo $JVERSION | awk -F. '{print $1}'`
# mijor=`echo $JVERSION | awk -F. '{print $2}'`
# if [ $major -le 1 ] && [ $mijor -lt 8 ]; then
# export JAVA_HOME=/usr/local/jdk1.8.0_65 #(使用jdk8请设置)
# export PATH=$JAVA_HOME/bin:$PATH
# fi
# 编译命令
mvn -U clean package -Dmaven.test.skip=true
local sc=$?
if [ $sc -ne 0 ];then
## 编译失败, 退出码为 非0
echo "$app_name build error"
exit $sc
else
echo -n "$app_name build ok, vsn="`gitversion`
fi
}
function make_output() {
# 新建output目录
rm -rf $output_dir &>/dev/null
mkdir -p $output_dir &>/dev/null
# 填充output目录, output内的内容 即为 线上部署内容
(
# cp -rf $control $output_dir && # 拷贝 control.sh 脚本 至output目录
cp -rf $create_mysql_table $output_dir && # 拷贝 sql 初始化脚本 至output目录
cp -rf $app_config_file $output_dir && # 拷贝 application.yml 至output目录
# 拷贝程序包到output路径
cp kafka-manager-web/target/${app_name}-*-SNAPSHOT.jar ${output_dir}/${app_name}.jar
echo -e "make output ok."
) || { echo -e "make output error"; exit 2; } # 填充output目录失败后, 退出码为 非0
}
function make_package() {
# 压缩output目录
(
tar cvzf ${app_name}.tar.gz ${output_dir}
echo -e "make package ok."
) || { echo -e "make package error"; exit 2; } # 压缩output目录失败后, 退出码为 非0
}
## internals
function gitversion() {
git log -1 --pretty=%h > $gitversion
local gv=`cat $gitversion`
echo "$gv"
}
##########################################
## main
## 其中,
## 1.进行编译
## 2.生成部署包output
## 3.生成tar.gz压缩包
##########################################
# 1.进行编译
build
# 2.生成部署包output
make_output
# 3.生成tar.gz压缩包
make_package
# 编译成功
echo -e "build done"
exit 0