2017-11-15 19:33:05 +08:00
|
|
|
#!/bin/bash
|
|
|
|
set -o errexit
|
|
|
|
|
|
|
|
# define package name
|
2017-11-17 15:25:38 +08:00
|
|
|
PROGRAM="gr-rainbond"
|
2017-11-15 19:33:05 +08:00
|
|
|
WORK_DIR=/go/src/github.com/goodrain/rainbond
|
2017-11-22 13:56:59 +08:00
|
|
|
DOCKER_PATH=./hack/contrib/docker/$1
|
2017-11-15 19:33:05 +08:00
|
|
|
BASE_NAME=rainbond
|
|
|
|
releasedir=./.release
|
|
|
|
distdir=${releasedir}/dist
|
2017-12-10 22:37:48 +08:00
|
|
|
gaopsdir=/hack/contrib/docker/node/gaops
|
2017-11-15 19:33:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
gitDescribe=$(git describe --tag|sed 's/^v//')
|
|
|
|
describe_items=($(echo $gitDescribe | tr '-' ' '))
|
2017-12-26 11:16:13 +08:00
|
|
|
branch_info=($(git branch | grep '^*' | cut -d ' ' -f 2))
|
2017-11-15 19:33:05 +08:00
|
|
|
describe_len=${#describe_items[@]}
|
2017-12-26 11:16:13 +08:00
|
|
|
VERSION=$(git branch | grep '^*' | cut -d ' ' -f 2 | tr '-' " " | awk '{print $2}')
|
2017-11-15 19:33:05 +08:00
|
|
|
git_commit=$(git log -n 1 --pretty --format=%h)
|
2017-12-01 12:32:31 +08:00
|
|
|
|
2017-11-15 19:33:05 +08:00
|
|
|
if [ $describe_len -ge 3 ];then
|
2018-01-03 18:10:20 +08:00
|
|
|
#buildRelease=${describe_items[-2]}.${describe_items[-1]}
|
|
|
|
buildRelease=${describe_items[*]: -2:1}.${describe_items[*]: -1}
|
2017-11-15 19:33:05 +08:00
|
|
|
else
|
|
|
|
buildRelease=0.$git_commit
|
|
|
|
fi
|
|
|
|
if [ -z "$VERSION" ];then
|
2018-01-15 10:31:47 +08:00
|
|
|
VERSION=cloud
|
2017-11-15 19:33:05 +08:00
|
|
|
fi
|
|
|
|
|
2017-12-01 12:32:31 +08:00
|
|
|
release_desc=${branch_info}-${VERSION}-${buildRelease}
|
|
|
|
|
2017-11-15 19:33:05 +08:00
|
|
|
function prepare() {
|
|
|
|
rm -rf $releasedir
|
|
|
|
mkdir -pv $releasedir/{tmp,dist}
|
|
|
|
path=$PWD
|
2017-12-10 21:20:23 +08:00
|
|
|
#git clone $gaops $releasedir/tmp
|
2017-11-15 19:33:05 +08:00
|
|
|
[ ! -d "$distdir/usr/local/" ] && mkdir -p $distdir/usr/local/bin
|
|
|
|
[ ! -d "$distdir/usr/share/gr-rainbond-node/gaops/" ] && mkdir -pv $distdir/usr/share/gr-rainbond-node/gaops
|
|
|
|
cd $releasedir/tmp
|
2017-12-10 22:37:48 +08:00
|
|
|
cp -a $path$gaopsdir/* ./
|
2017-11-21 16:45:02 +08:00
|
|
|
tar zcf ../dist/usr/share/gr-rainbond-node/gaops/gaops.tgz ./
|
2017-11-15 19:33:05 +08:00
|
|
|
cd $path
|
|
|
|
rm -rf $releasedir/tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
function build() {
|
2017-11-17 15:25:38 +08:00
|
|
|
echo "---> Build Binary For ACP"
|
2018-01-17 23:29:09 +08:00
|
|
|
echo "acp plugins version:$release_desc"
|
2018-03-08 09:50:26 +08:00
|
|
|
# sed -i "s/0.0.0/$release_desc/g" ./cmd/version.go
|
2017-11-17 15:25:38 +08:00
|
|
|
echo "build rainbond-node"
|
2017-12-18 14:59:29 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s' -o $releasedir/dist/usr/local/bin/${BASE_NAME}-node ./cmd/node
|
2017-11-17 15:25:38 +08:00
|
|
|
echo "build rainbond-grctl"
|
2017-12-18 14:59:29 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s' -o $releasedir/dist/usr/local/bin/${BASE_NAME}-grctl ./cmd/grctl
|
2018-03-08 09:50:26 +08:00
|
|
|
# sed -i "s/$release_desc/0.0.0/g" ./cmd/version.go
|
2017-11-15 19:33:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function build::rpm() {
|
|
|
|
echo "---> Make Build RPM"
|
|
|
|
source "hack/build-rpm.sh"
|
|
|
|
}
|
|
|
|
|
2017-11-20 12:03:39 +08:00
|
|
|
function build::deb() {
|
|
|
|
echo "---> Make Build DEB"
|
|
|
|
source "hack/build-deb.sh"
|
|
|
|
}
|
|
|
|
|
2017-11-22 13:56:59 +08:00
|
|
|
function build::image() {
|
|
|
|
echo "---> Build Image:$1 FOR ACP"
|
|
|
|
|
|
|
|
if [ "$1" = "eventlog" ];then
|
|
|
|
docker build -t goodraim.me/event-build:v1 ${DOCKER_PATH}/build
|
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} goodraim.me/event-build:v1 go build -ldflags '-w -s' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/eventlog
|
2017-11-22 15:08:35 +08:00
|
|
|
elif [ "$1" = "chaos" ];then
|
2017-12-18 14:59:29 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/builder
|
2017-11-22 13:56:59 +08:00
|
|
|
else
|
2017-12-18 14:59:29 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
|
2017-11-22 13:56:59 +08:00
|
|
|
fi
|
|
|
|
cd ${DOCKER_PATH}
|
|
|
|
sed "s/__RELEASE_DESC__/${release_desc}/" Dockerfile > Dockerfile.release
|
2017-12-26 11:16:13 +08:00
|
|
|
docker build -t ${BASE_NAME}/rbd-$1:${VERSION} -f Dockerfile.release .
|
2017-11-22 13:56:59 +08:00
|
|
|
rm -f ./Dockerfile.release
|
|
|
|
rm -f ./${BASE_NAME}-$1
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:33:05 +08:00
|
|
|
case $1 in
|
|
|
|
build)
|
|
|
|
prepare
|
|
|
|
build
|
|
|
|
;;
|
|
|
|
rpm)
|
2017-11-22 13:56:59 +08:00
|
|
|
prepare
|
|
|
|
build
|
2017-11-15 19:33:05 +08:00
|
|
|
build::rpm
|
|
|
|
;;
|
2017-11-20 12:03:39 +08:00
|
|
|
deb)
|
2017-11-22 13:56:59 +08:00
|
|
|
prepare
|
|
|
|
build
|
2017-11-20 12:03:39 +08:00
|
|
|
build::deb
|
|
|
|
;;
|
2017-11-30 21:37:52 +08:00
|
|
|
dev_deb)
|
|
|
|
build::deb
|
|
|
|
;;
|
|
|
|
dev_rpm)
|
|
|
|
build::rpm
|
|
|
|
;;
|
2017-11-22 13:56:59 +08:00
|
|
|
pkg)
|
2017-11-15 19:33:05 +08:00
|
|
|
prepare
|
|
|
|
build
|
|
|
|
build::rpm
|
2017-11-20 12:03:39 +08:00
|
|
|
build::deb
|
2017-11-15 19:33:05 +08:00
|
|
|
;;
|
2017-11-22 13:56:59 +08:00
|
|
|
*)
|
|
|
|
build::image $1
|
|
|
|
;;
|
2017-11-15 19:33:05 +08:00
|
|
|
esac
|