2017-11-15 19:33:05 +08:00
|
|
|
#!/bin/bash
|
|
|
|
set -o errexit
|
|
|
|
|
|
|
|
# define package name
|
|
|
|
WORK_DIR=/go/src/github.com/goodrain/rainbond
|
|
|
|
BASE_NAME=rainbond
|
2018-09-14 13:19:44 +08:00
|
|
|
GO_VERSION=1.11
|
2017-11-15 19:33:05 +08:00
|
|
|
|
2018-11-07 15:03:36 +08:00
|
|
|
VERSION=3.7.2
|
2018-05-21 16:21:27 +08:00
|
|
|
buildTime=$(date +%F-%H)
|
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
|
|
|
|
2018-11-07 15:03:36 +08:00
|
|
|
release_desc=${VERSION}-${git_commit}-${buildTime}
|
2017-11-15 19:33:05 +08:00
|
|
|
|
2018-11-07 15:03:36 +08:00
|
|
|
build::node() {
|
|
|
|
local releasedir=./.release
|
|
|
|
local distdir=$releasedir/dist/usr/local
|
|
|
|
[ ! -d "$distdir" ] && mkdir -p $distdir/bin || rm -rf $distdir/bin/*
|
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-07-26 15:58:30 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/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-07-26 15:58:30 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o $releasedir/dist/usr/local/bin/grctl ./cmd/grctl
|
2018-08-02 14:11:56 +08:00
|
|
|
echo "build certutil"
|
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o $releasedir/dist/usr/local/bin/grcert ./cmd/certutil
|
2018-11-07 15:03:36 +08:00
|
|
|
pushd $distdir
|
2018-06-08 18:02:06 +08:00
|
|
|
tar zcf pkg.tgz `find . -maxdepth 1|sed 1d`
|
|
|
|
|
|
|
|
cat >Dockerfile <<EOF
|
|
|
|
FROM alpine:3.6
|
|
|
|
COPY pkg.tgz /
|
|
|
|
EOF
|
2018-11-07 15:03:36 +08:00
|
|
|
docker build -t ${BASE_NAME}/cni:rbd_v$VERSION .
|
|
|
|
docker push ${BASE_NAME}/cni:rbd_v$VERSION
|
|
|
|
popd
|
2017-11-20 12:03:39 +08:00
|
|
|
}
|
|
|
|
|
2018-11-07 15:03:36 +08:00
|
|
|
build::binary() {
|
|
|
|
echo "---> build binary:$1"
|
|
|
|
local DOCKER_PATH=./hack/contrib/docker/$1
|
2018-07-26 15:58:30 +08:00
|
|
|
HOME=`pwd`
|
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-19 17:13:05 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} goodraim.me/event-build:v1 go build -ldflags "-w -s -X github.com/goodrain/rainbond/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-07-26 15:58:30 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/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-07-26 15:58:30 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -extldflags '-static' -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -tags 'netgo static_build' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
|
2017-11-22 13:56:59 +08:00
|
|
|
else
|
2018-07-26 15:58:30 +08:00
|
|
|
docker run --rm -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
|
2017-11-22 13:56:59 +08:00
|
|
|
fi
|
2018-11-07 15:03:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
build::image() {
|
|
|
|
local REPO_PATH="$PWD"
|
|
|
|
pushd ./hack/contrib/docker/$1
|
|
|
|
echo "---> build binary:$1"
|
|
|
|
local DOCKER_PATH="./hack/contrib/docker/$1"
|
|
|
|
if [ "$1" = "eventlog" ];then
|
|
|
|
docker build -t goodraim.me/event-build:v1 build
|
|
|
|
docker run --rm -v ${REPO_PATH}:${WORK_DIR} -w ${WORK_DIR} goodraim.me/event-build:v1 go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/eventlog
|
|
|
|
elif [ "$1" = "chaos" ];then
|
|
|
|
docker run --rm -v ${REPO_PATH}:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/builder
|
|
|
|
elif [ "$1" = "monitor" ];then
|
|
|
|
docker run --rm -v ${REPO_PATH}:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -extldflags '-static' -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -tags 'netgo static_build' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
|
|
|
|
else
|
|
|
|
docker run --rm -v ${REPO_PATH}:${WORK_DIR} -w ${WORK_DIR} -it golang:${GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
|
|
|
|
fi
|
|
|
|
echo "---> build image:$1"
|
|
|
|
sed "s/__RELEASE_DESC__/${release_desc}/" Dockerfile > Dockerfile.release
|
|
|
|
docker build -t ${BASE_NAME}/rbd-$1:${VERSION} -f Dockerfile.release .
|
|
|
|
docker push ${BASE_NAME}/rbd-$1:${VERSION}
|
|
|
|
rm -f ./Dockerfile.release
|
|
|
|
rm -f ./${BASE_NAME}-$1
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
build::all(){
|
|
|
|
local build_items=(api chaos entrance monitor mq webcli worker eventlog)
|
|
|
|
for item in ${build_items[@]}
|
|
|
|
do
|
|
|
|
build::image $item
|
|
|
|
done
|
|
|
|
build::node
|
2017-11-22 13:56:59 +08:00
|
|
|
}
|
|
|
|
|
2017-11-15 19:33:05 +08:00
|
|
|
case $1 in
|
2018-11-07 15:03:36 +08:00
|
|
|
node)
|
|
|
|
build::node
|
2018-07-16 15:56:31 +08:00
|
|
|
;;
|
2017-11-22 13:56:59 +08:00
|
|
|
*)
|
2018-11-07 15:03:36 +08:00
|
|
|
if [ "$1" = "all" ];then
|
|
|
|
build::all
|
|
|
|
else
|
|
|
|
build::image $1
|
|
|
|
fi
|
2017-11-22 13:56:59 +08:00
|
|
|
;;
|
2018-05-31 17:08:47 +08:00
|
|
|
esac
|