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
|
|
|
|
|
|
|
|
|
2018-05-21 16:21:27 +08:00
|
|
|
VERSION=$(git branch | grep '^*' | cut -d ' ' -f 2 | awk -F'V' '{print $2}')
|
|
|
|
buildTime=$(date +%F-%H)
|
2017-11-15 19:33:05 +08:00
|
|
|
git_commit=$(git log -n 1 --pretty --format=%h)
|
|
|
|
if [ -z "$VERSION" ];then
|
2018-01-15 10:31:47 +08:00
|
|
|
VERSION=cloud
|
2017-11-15 19:33:05 +08:00
|
|
|
fi
|
2018-05-21 16:21:27 +08:00
|
|
|
release_desc=${VERSION}-${git_commit}-${buildTime}
|
2017-12-01 12:32:31 +08:00
|
|
|
|
2017-11-15 19:33:05 +08:00
|
|
|
function prepare() {
|
|
|
|
rm -rf $releasedir
|
|
|
|
mkdir -pv $releasedir/{tmp,dist}
|
|
|
|
path=$PWD
|
|
|
|
[ ! -d "$distdir/usr/local/" ] && mkdir -p $distdir/usr/local/bin
|
2018-05-21 16:21:27 +08:00
|
|
|
|
2017-11-15 19:33:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function build() {
|
2018-05-21 16:21:27 +08:00
|
|
|
echo "---> Build Binary For RBD"
|
|
|
|
echo "rbd plugins version:$release_desc"
|
2018-06-08 18:02:06 +08:00
|
|
|
|
|
|
|
echo "build node"
|
2018-06-15 13:31:39 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s -X cmd.version=$(release_desc)' -o $releasedir/dist/usr/local/bin/node ./cmd/node
|
2018-06-08 18:02:06 +08:00
|
|
|
echo "build grctl"
|
2018-06-15 13:31:39 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s -X cmd.version=$(release_desc)' -o $releasedir/dist/usr/local/bin/grctl ./cmd/grctl
|
2018-06-08 18:02:06 +08:00
|
|
|
|
|
|
|
cd $releasedir/dist/usr/local/
|
|
|
|
tar zcf pkg.tgz `find . -maxdepth 1|sed 1d`
|
|
|
|
|
|
|
|
cat >Dockerfile <<EOF
|
|
|
|
FROM alpine:3.6
|
|
|
|
COPY pkg.tgz /
|
|
|
|
EOF
|
|
|
|
docker build -t rainbond/cni:rbd_v3.6 .
|
|
|
|
|
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() {
|
2018-05-21 16:21:27 +08:00
|
|
|
echo "---> Build Image:$1 FOR RBD"
|
2017-11-22 13:56:59 +08:00
|
|
|
|
|
|
|
if [ "$1" = "eventlog" ];then
|
|
|
|
docker build -t goodraim.me/event-build:v1 ${DOCKER_PATH}/build
|
2018-06-15 13:31:39 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} goodraim.me/event-build:v1 go build -ldflags '-w -s -X cmd.version=$(release_desc)' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/eventlog
|
2017-11-22 15:08:35 +08:00
|
|
|
elif [ "$1" = "chaos" ];then
|
2018-06-15 13:31:39 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s -X cmd.version=$(release_desc)' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/builder
|
2018-06-01 10:51:05 +08:00
|
|
|
elif [ "$1" = "monitor" ];then
|
2018-06-15 13:31:39 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags "-w -s -extldflags '-static' -X cmd.version=$(release_desc)" -tags 'netgo static_build' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
|
2018-06-02 10:45:11 +08:00
|
|
|
#go build -ldflags "-w -s -extldflags '-static'" -tags 'netgo static_build' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/monitor
|
2017-11-22 13:56:59 +08:00
|
|
|
else
|
2018-06-15 13:31:39 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:1.8.3 go build -ldflags '-w -s -X cmd.version=$(release_desc)' -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
|
|
|
|
;;
|
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
|
|
|
|
;;
|
2018-05-31 17:08:47 +08:00
|
|
|
esac
|