Skip to content

Instantly share code, notes, and snippets.

@hoto17296
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoto17296/c4eabeeedab9e6ae02aa to your computer and use it in GitHub Desktop.
Save hoto17296/c4eabeeedab9e6ae02aa to your computer and use it in GitHub Desktop.
デプロイツールを使う程でもないときの git pull するだけのデプロイスクリプト
#!/bin/sh
TARGET='staging'
APPDIR='~/app'
BRANCH='master'
while getopts :bdt: OPT
do
case $OPT in
'b' ) BRANCH="$OPTARG" ;;
'd' ) APPDIR="$OPTARG" ;;
't' ) TARGET="$OPTARG" ;;
* ) echo "Usage: `basename $0` [-t TARGET] [-d APPDIR] [-b BRANCH]" 1>&2
exit 1 ;;
esac
done
case $TARGET in
'staging' ) HOSTS=( app-stg-web-1 app-stg-web-2 ) ;;
* ) echo "Undefined target '${TARGET}'." 1>&2
exit 1 ;;
esac
for HOST in ${HOSTS[@]}; do
REMOTE_BRANCH=`ssh ${HOST} "cd ${APPDIR} && git rev-parse --abbrev-ref HEAD"`
if [ $BRANCH != $REMOTE_BRANCH ]; then
echo "Oops, ${HOST} branch is ${REMOTE_BRANCH}." 1>&2
exit 1
fi
done
for HOST in ${HOSTS[@]}; do
ssh $HOST "cd ${APPDIR} && git pull"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment