-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
87 lines (68 loc) · 1.7 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
#!/bin/bash
set -e
FAIL=1
OK=0
WORKSPACE=$(cd $(dirname $0) && pwd -P)
GOVERSION="go1.14.4"
function check_go_version() {
local version=$(go version | awk '{print $3}' | sed s/[[:space:]]//g)
if [[ "${version}" != "${GOVERSION}" ]]; then
echo "version not matched. expect: " ${GOVERSION} " actual: " ${version}
return ${FAIL}
fi
return ${OK}
}
function reset_env() {
rm -rf ${OUTPUT}
mkdir -p ${OUTPUT}/bin/
mkdir -p ${OUTPUT}/conf/
export GOPROXY="https://goproxy.io/,direct"
export GO111MODULE=auto
echo -e "go env:\n"
go env
echo -e "\n"
}
BuildTime=$(date "+%F %T")
GoVersion=$(go version)
AppName="openapi"
AppVersion=${AppName}"_"$(date "+%F %T" | awk '{print $1"_"$2}')
OUTPUT="output"
function build() {
go build -o ${APPNAME}
if [[ $? != 0 ]];then
echo "compile failed"
return ${FAIL}
fi
mkdir ${OUTPUT}/tools
cd tools
for d in $(ls); do
app=$(basename ${d})
cd ${WORKSPACE}/tools/${app}
go build -o ${app}
mv ${app} ${WORKSPACE}/${OUTPUT}/tools/
cp *.sh ${WORKSPACE}/${OUTPUT}/tools/
done
cd ${WORKSPACE}
cp -rf ./conf/* ./${OUTPUT}/conf
cp -rf ./control.sh ./${OUTPUT}
cp -rf ./${APPNAME} ./${OUTPUT}/bin
cp supervisord/* ./${OUTPUT}/bin
mkdir -p ${OUTPUT}/logs
chmod +x supervisord/supervisord
chmod +x ${OUTPUT}/*.sh
chmod +x ${OUTPUT}/bin/${APPNAME}
chmod +x ${OUTPUT}/tools/*
cd ${OUTPUT}
tar -zcf ${APPNAME}.tar.gz *
#find ./ -type d -name .git |xargs -i rm -rf {}
}
function main() {
check_go_version
if [[ $? -ne ${OK} ]]; then
return ${FAIL}
fi
reset_env
build
return $?
}
main "$@"