chore(scripts): add deploy bitxhub scripts

add deploy scripts for compiling linux binary and deploying to server
This commit is contained in:
Alexader 2020-04-03 14:37:40 +08:00
parent 123d51756d
commit 1a371bd180
2 changed files with 114 additions and 1 deletions

2
.gitignore vendored
View File

@ -10,7 +10,7 @@ node_modules
dump
build
build_solo
build.tar.gz
build*.tar.gz
cover.out
coverage.out
pid

113
scripts/deploy.sh Normal file
View File

@ -0,0 +1,113 @@
set -e
source x.sh
CURRENT_PATH=$(pwd)
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
BUILD_PATH=${CURRENT_PATH}/build
APP_VERSION=$(git describe --tag)
# help prompt message
function printHelp() {
print_blue "Usage: "
echo " deploy.sh [-a <bitxhub_addr>] [-n <node_num>] [-r <if_recompile>] [-u <username>] [-p <build_path>]"
echo " - 'a' - the ip address of bitxhub node"
echo " - 'n' - node number to be deployed in one server"
echo " - 'r' - if need to recompile locally"
echo " - 'u' - the username of remote linux server"
echo " - 'p' - the deploy path relative to HOME directory in linux server"
echo " deploy.sh -h (print this message)"
}
function deploy() {
print_blue "1. Generate config"
bash config.sh "$NODE_NUM"
print_blue "2. Compile bitxhub"
if [[ $IF_RECOMPILE == true ]]; then
bash cross_compile.sh linux-amd64 ${PROJECT_PATH}
else
echo "Do not need compile"
fi
## prepare deploy package
cd "${CURRENT_PATH}"
cp ../bin/bitxhub_linux-amd64 "${BUILD_PATH}"/bitxhub
cp ../internal/plugins/build/*.so "${BUILD_PATH}"/
tar cf build${APP_VERSION}.tar.gz build
print_blue "3. Deploy bitxhub"
cd "${CURRENT_PATH}"
scp build${APP_VERSION}.tar.gz ${USERNAME}@"${BITXHUB_ADDR}":${SERVER_BUILD_PATH}
ssh -t ${USERNAME}@"${BITXHUB_ADDR}" '
cd '${SERVER_BUILD_PATH}'
CURRENT_PATH=$(pwd)
BUILD_PATH=${CURRENT_PATH}/build
N='$NODE_NUM'
function splitWindow() {
tmux splitw -v -p 50
tmux splitw -h -p 50
tmux selectp -t 0
tmux splitw -h -p 50
}
function start() {
cd ${CURRENT_PATH}
rm -rf build
tar -xf build.tar.gz
pkill -9 bitxhub
tmux kill-session -t bitxhub
tmux new -d -s bitxhub
cd build
for ((i=0;i<N/4;i=i+1)); do
splitWindow
tmux new-window
done
splitWindow
for ((i = 0;i < N;i = i + 1)); do
tmux selectw -t $(($i / 4))
tmux selectp -t $(($i % 4))
cp bitxhub ./node$(($i + 1))/
if [ ! -d ./node$(($i + 1))/plugins ]; then
mkdir ./node$(($i + 1))/plugins
fi
cp *.so ./node$(($i + 1))/plugins/
tmux send-keys "cd ${BUILD_PATH} && ./node$(($i + 1))/bitxhub --repo=${BUILD_PATH}/node$(($i + 1)) start" C-m
done
tmux selectw -t 0
}
start
tmux attach-session -t bitxhub
'
}
while getopts "h?a:n:r:u:p:" opt; do
case "$opt" in
h | \?)
printHelp
exit 0
;;
a)
BITXHUB_ADDR=$OPTARG
;;
n)
NODE_NUM=$OPTARG
;;
r)
IF_RECOMPILE=$OPTARG
;;
u)
USERNAME=$OPTARG
;;
p)
SERVER_BUILD_PATH=/home/${USERNAME}/$OPTARG
;;
esac
done
deploy