Last active
August 29, 2015 14:13
-
-
Save hoto17296/c4eabeeedab9e6ae02aa to your computer and use it in GitHub Desktop.
デプロイツールを使う程でもないときの git pull するだけのデプロイスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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