代码拉取完成,页面将自动刷新
#!/bin/bash
source ./env
_usage() {
echo "$0 [options] ip..."
echo "options:"
echo " -a area_dir"
echo " -d deploy-arg. can be multiple"
exit 1
}
# parse args
set -- $(getopt :a:d: $@)
while getopts a:d: opt; do
case $opt in
a)
AREA_DIR=$OPTARG
;;
d)
DEPLOY_ARGS+=" $OPTARG"
;;
?)
_usage
;;
esac
done
shift $((OPTIND - 1))
# check
[ ! $AREA_DIR ] && _usage
[ ! $1 ] && _usage
read -p "continue to release? [Yes/No]" x
[ "$x" != "Yes" ] && exit 1
# -------------------------------------
set -e
# build
go clean -cache
[ -d bin ] && mv bin bin_old
./build.sh
# retrive code rev
echo "retrieving code version ..."
BRANCH_CODE=$(git branch | grep \* | awk '{print $2}')
COMMIT=$(git log | head -1 | awk '{print $2}')
# copy version file
cp .ver/VER_${BRANCH_CODE} bin/
cat >> bin/VER_${BRANCH_CODE} << EOF
code:
$BRANCH_CODE $COMMIT
EOF
# pack
echo "packing ..."
tarfile=${PROJ_NAME}-${BRANCH_CODE}.$(date +%Y%m%d.%H%M).tar.gz
$TAR \
--exclude='**/node_modules/.bin' \
--exclude='**/node_modules/**/.bin' \
--exclude='**/node_modules/**/bin' \
-hczf $tarfile bin
# upload
for IP in $@; do
echo "uploading ($IP) ..."
scp $tarfile game@$IP:$WORK_DIR/$AREA_DIR
done
# clean up
echo "cleaning up ..."
rm $tarfile
rm -rf bin
[ -d bin_old ] && mv bin_old bin
# exec deploy.sh if there's any in remote
for IP in $@; do
echo "deploying ($IP) ..."
ssh game@$IP "
if [ -x $WORK_DIR/$AREA_DIR/dev_auto_update.sh ]; then
cd $WORK_DIR/$AREA_DIR
./dev_auto_update.sh $tarfile $DEPLOY_ARGS
fi
"
done
# done
echo -e "\033[32mDone.\033[0m"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。