-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathbuild.sh
executable file
·81 lines (72 loc) · 2.06 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
#!/bin/bash
set -eux
source scripts/version.sh
source scripts/.variables.sh
ProjectName=${ProjectName:-"github.com/xiaomeng79/istio-micro"}
Version=${Version:-"unknown-version"}
GoVersion=${GoVersion:-$(go version)}
#GoVersion=${GoVersion:-$(go version | awk '{print $3}')}
GitCommit=${GitCommit:-$(git rev-parse --short HEAD 2> /dev/null || true)}
BuiltTime=${BuiltTime:-$(date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')}
#TARGET=${TARGET:-'main'}
#GOOS=$(go env GOHOSTOS)
#
#if [ "${GOOS}" = "windows" ]; then
# TARGET="${TARGET}.exe"
#fi
#build
build() {
#判断bin是否存在
if [ ! -d deployments/bin ];then
mkdir -p deployments/bin
fi
#build
dirname=./cmd/$1
if [ -d $dirname ];then
for f in $dirname/$2.go; do \
if [ -f $f ];then \
# CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -installsuffix cgo -ldflags '-w' -i -o deployments/bin/$1_$2/$1_$2 -tags $1_$2 ./cmd/$1/
buildapp $1 $2
echo build over: $1_$2; \
fi \
done \
fi
}
#build app
buildapp() {
mkdir -p deployments/bin/${1}_${2}/sqlupdate && \
CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -installsuffix cgo -ldflags \
" \
-w \
-X '${ProjectName}/version.Version=${Version}' \
-X '${ProjectName}/version.GoVersion=${GoVersion}' \
-X '${ProjectName}/version.GitCommit=${GitCommit}' \
-X '${ProjectName}/version.BuiltTime=${BuiltTime}' \
" \
-i -o deployments/bin/${1}_${2}/${1}_${2} -tags ${1}_${2} ./cmd/${1}/
}
#全部build
allbuild() {
build srv user
build srv account
build srv socket
build api backend
build api frontend
}
#判断如何build
case $1 in
allbuild) echo "全部build"
allbuild
;;
build) echo "build:"$2,$3
if [ -z $2 -o -z $3 ];then
echo "参数错误"
exit 2
fi
build $2 $3
;;
*)
echo "build error"
exit 2
;;
esac