Rainbond/localbuild.sh

55 lines
1.4 KiB
Bash
Raw Normal View History

2018-11-07 15:03:36 +08:00
#!/bin/bash
set -o errexit
# define package name
releasedir=./.release
distdir=${releasedir}/dist
VERSION=$(git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)
2018-11-07 15:03:36 +08:00
buildTime=$(date +%F-%H)
git_commit=$(git log -n 1 --pretty --format=%h)
release_desc=${VERSION}-${git_commit}-${buildTime}
function prepare() {
rm -rf $releasedir
mkdir -pv $releasedir/{tmp,dist}
[ ! -d "$distdir/usr/local/" ] && mkdir -p $distdir/usr/local/bin
}
2020-09-06 11:09:48 +08:00
build_items=(api builder grctl monitor mq node webcli worker eventlog init-probe mesh-data-panel)
2018-11-07 15:03:36 +08:00
function localbuild() {
if [ "$1" = "all" ];then
for item in "${build_items[@]}"
2018-11-07 15:03:36 +08:00
do
echo "build local ${item}"
2020-09-06 11:09:48 +08:00
go build -ldflags "-X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o _output/${GOOS}/${VERSION}/rainbond-$item ./cmd/$item
2018-11-07 15:03:36 +08:00
done
else
echo "build local $1 ${VERSION}"
2018-12-01 16:56:03 +08:00
outputname="_output/${GOOS}/${VERSION}/rainbond-$1"
if [ "$GOOS" = "windows" ];then
outputname="_output/${GOOS}/${VERSION}/rainbond-$1.exe"
fi
2020-09-06 11:09:48 +08:00
ldflags="-X github.com/goodrain/rainbond/cmd.version=${release_desc}"
2018-12-01 16:56:03 +08:00
if [ "$STATIC" = "true" ];then
ldflags="${ldflags} -extldflags '-static'"
fi
CGO_ENABLED=1 go build -v -ldflags "${ldflags}" -o ${outputname} ./cmd/$1
2018-11-07 15:03:36 +08:00
fi
}
case $1 in
*)
prepare
2018-12-01 16:56:03 +08:00
if [ "$1" = "all" ];then
for item in "${build_items[@]}"
2018-12-01 16:56:03 +08:00
do
localbuild $item
done
fi
2018-11-13 10:47:14 +08:00
localbuild $1
2018-11-07 15:03:36 +08:00
;;
esac