Rainbond/release.sh

159 lines
6.6 KiB
Bash
Raw Normal View History

#!/bin/bash
set -o errexit
# define package name
WORK_DIR=/go/src/github.com/goodrain/rainbond
BASE_NAME=rainbond
IMAGE_BASE_NAME=rainbond
if [ $BUILD_IMAGE_BASE_NAME ];
then
IMAGE_BASE_NAME=${BUILD_IMAGE_BASE_NAME}
fi
2019-07-24 16:01:59 +08:00
GO_VERSION=1.11-stretch
GATEWAY_GO_VERSION=1.11-alpine3.8
2019-07-12 22:18:58 +08:00
if [ -z "$VERSION" ];then
if [ -z "$TRAVIS_TAG" ]; then
if [ -z "$TRAVIS_BRANCH" ]; then
2019-07-12 22:18:58 +08:00
VERSION=V5.1-dev
else
VERSION=$TRAVIS_BRANCH-dev
fi
else
VERSION=$TRAVIS_TAG
fi
2019-03-29 22:17:27 +08:00
fi
2019-07-12 22:18:58 +08:00
2018-05-21 16:21:27 +08:00
buildTime=$(date +%F-%H)
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}
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"
2019-04-11 18:49:45 +08:00
case $1 in
node)
echo "build node"
2019-09-16 17:35:18 +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}" -tags license -o $releasedir/dist/usr/local/bin/node ./cmd/node
2019-04-11 18:49:45 +08:00
;;
grctl)
echo "build grctl"
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
;;
certutil)
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
;;
*)
echo "build node"
2019-09-16 17:35:18 +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}" -tags license -o $releasedir/dist/usr/local/bin/node ./cmd/node
2019-04-11 18:49:45 +08:00
echo "build grctl"
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
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
pushd $distdir
tar zcf pkg.tgz `find . -maxdepth 1|sed 1d`
2018-06-08 18:02:06 +08:00
2019-04-11 18:49:45 +08:00
cat >Dockerfile <<EOF
2018-06-08 18:02:06 +08:00
FROM alpine:3.6
COPY pkg.tgz /
EOF
2019-04-11 18:49:45 +08:00
docker build -t ${BASE_NAME}/cni:rbd_$VERSION .
if [ "$1" = "push" ];then
docker push ${BASE_NAME}/cni:rbd_$VERSION
fi
popd
;;
esac
2017-11-20 12:03:39 +08:00
}
2018-11-07 15:03:36 +08:00
build::binary() {
echo "---> build binary:$1"
2018-12-01 18:11:32 +08:00
local OUTPATH=./_output/$GOOS/${BASE_NAME}-$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-12-01 18:11:32 +08:00
docker run --rm -e GOOS=${GOOS} -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 ${OUTPATH} ./cmd/eventlog
2017-11-22 15:08:35 +08:00
elif [ "$1" = "chaos" ];then
2018-12-01 18:11:32 +08:00
docker run --rm -e GOOS=${GOOS} -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 ${OUTPATH} ./cmd/builder
elif [ "$1" = "monitor" ];then
2018-12-01 18:11:32 +08:00
docker run --rm -e GOOS=${GOOS} -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 ${OUTPATH} ./cmd/$1
elif [ "$1" = "gateway" ];then
docker run --rm -e GOOS=${GOOS} -v `pwd`:${WORK_DIR} -w ${WORK_DIR} -it golang:${GATEWAY_GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${OUTPATH} ./cmd/$1
2017-11-22 13:56:59 +08:00
else
2019-09-16 17:35:18 +08:00
docker run --rm -e GOOS=${GOOS} -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}" -tags license -o ${OUTPATH} ./cmd/$1
2018-12-01 18:11:32 +08:00
fi
if [ "$GOOS" = "windows" ];then
mv $OUTPATH ${OUTPATH}.exe
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
elif [ "$1" = "gateway" ];then
docker run --rm -v ${REPO_PATH}:${WORK_DIR} -w ${WORK_DIR} -it golang:${GATEWAY_GO_VERSION} go build -ldflags "-w -s -X github.com/goodrain/rainbond/cmd.version=${release_desc}" -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
2019-06-26 10:22:18 +08:00
elif [ "$1" = "mesh-data-panel" ];then
echo "mesh-data-panel not need build";
2018-11-07 15:03:36 +08:00
else
2019-09-16 17:35:18 +08:00
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}" -tags 'license' -o ${DOCKER_PATH}/${BASE_NAME}-$1 ./cmd/$1
2018-11-07 15:03:36 +08:00
fi
echo "---> build image:$1"
sed "s/__RELEASE_DESC__/${release_desc}/" Dockerfile > Dockerfile.release
docker build -t ${IMAGE_BASE_NAME}/rbd-$1:${VERSION} -f Dockerfile.release .
2018-12-01 15:18:40 +08:00
if [ "$2" = "push" ];then
2019-01-07 15:32:03 +08:00
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker push ${IMAGE_BASE_NAME}/rbd-$1:${VERSION}
2018-11-21 17:35:07 +08:00
fi
2018-11-07 15:03:36 +08:00
rm -f ./Dockerfile.release
rm -f ./${BASE_NAME}-$1
popd
}
build::all(){
2019-06-26 09:54:57 +08:00
local build_items=(api chaos gateway monitor mq webcli worker eventlog init-probe mesh-data-panel)
2018-11-07 15:03:36 +08:00
for item in ${build_items[@]}
do
2018-11-21 17:35:07 +08:00
build::image $item $1
2018-11-07 15:03:36 +08:00
done
2018-12-01 15:18:40 +08:00
build::node $1
2017-11-22 13:56:59 +08:00
}
case $1 in
2018-11-07 15:03:36 +08:00
node)
2018-12-01 15:18:40 +08:00
build::node $2
;;
2018-12-01 18:11:32 +08:00
binary)
if [ "$2" = "all" ];then
2019-02-28 14:52:39 +08:00
build_items=(chaos grctl node gateway monitor mq worker eventlog api init-probe)
2018-12-01 18:11:32 +08:00
for item in ${build_items[@]}
do
build::binary $item $1
done
else
build::binary $2
fi
;;
2017-11-22 13:56:59 +08:00
*)
2018-11-07 15:03:36 +08:00
if [ "$1" = "all" ];then
2018-11-21 17:35:07 +08:00
build::all $2
2018-11-07 15:03:36 +08:00
else
2018-11-21 17:35:07 +08:00
build::image $1 $2
2018-11-07 15:03:36 +08:00
fi
2017-11-22 13:56:59 +08:00
;;
2018-12-06 10:50:02 +08:00
esac