Skip to content

Instantly share code, notes, and snippets.

@alexsunday
Last active August 29, 2015 14:19
Show Gist options
  • Save alexsunday/8150026921e78f9addab to your computer and use it in GitHub Desktop.
Save alexsunday/8150026921e78f9addab to your computer and use it in GitHub Desktop.
自动部署git应用到服务器,服务器端的 bare仓库的hooks脚本
#!/usr/bin/env bash
APP_NAME=huate
DEPLOY=deploy.sh
APP_DIR=/wwwroot/huateBackend
BAK_DIR=/home/pyapp/bak
unset GIT_DIR
read oldrev newrev refname
if [ -n $oldrev ] && [ -n $newrev ] && [ -n $refname ];
then
echo 'Welcome to auto deploy sys v0.1'
echo 'powered by suncc@useease'
else
echo 'CANNOT RUN direct by shell'
fi
branch=`echo $refname|awk -F"/" '{print $3}'`
if [ "x$refname" != "xrefs/heads/release" ];
then
echo '*******************'
echo "CUR BRANCH $branch"
echo ' MUST BE release'
echo ' PUSH FAIL.'
echo '*******************'
exit 1
fi
if [ ! -d $APP_DIR ];
then
echo "APPDIR $APP_DIR NOT EXISTS, FAIL!"
exit 1
fi
if [ ! -d $BAK_DIR ];
then
echo "BACKUP DIR $BAK_DIR NOT EXISTS, BACKUP NEED IT, FAIL!"
exit 1
fi
cd $APP_DIR
pwd
bak_filename=${APP_NAME}_`date +%Y%m%d%H%M%S`.tar.gz
echo "[EXEC] tar czf $BAK_DIR/$bak_filename . exclude pyc && static "
tar czf $BAK_DIR/$bak_filename . --exclude *.pyc --exclude static --exclude .git --exclude *.out
echo "[EXEC] git reset --hard HEAD"
git reset --hard HEAD
echo "[EXEC] git clean -f"
git clean -f
echo "[EXEC] git checkout release"
git checkout release
echo "[EXEC] git pull"
git fetch
git merge origin/release
if [ -f "$DEPLOY" ];
then
echo "FOUND $DEPLOY, EXEC IT"
echo "[EXEC] source $DEPLOY"
source $DEPLOY
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment