Last active
August 29, 2015 14:00
-
-
Save psaia/11226368 to your computer and use it in GitHub Desktop.
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
######################################## | |
# File: /usr/bin/deploy | |
######################################## | |
#!/bin/sh | |
REF_NAME=$1 | |
DEPLOY_BRANCH=$2 | |
REMOTE_PROJECT_PATH=$3 | |
REMOTE_SERVER=$4 | |
REMOTE_PORT=$5 | |
REMOTE_USER=$6 | |
_DIR_NAME=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |
_TMP_PATH=/tmp | |
_FULL_DIR_PATH=$_TMP_PATH/$_DIR_NAME | |
if [[ $# -eq 0 ]] ; then | |
echo "Arguments: refname branch remotepath server port user" | |
exit 1 | |
fi | |
if [ $REF_NAME = "refs/heads/$DEPLOY_BRANCH" ] | |
then | |
echo "### Deploying to $DEPLOY_BRANCH" | |
echo "### Creating temporary checkout of $DEPLOY_BRANCH." | |
mkdir $_FULL_DIR_PATH | |
GIT_WORK_TREE=$_FULL_DIR_PATH git checkout -q -f $DEPLOY_BRANCH | |
echo "### Copying to remote server: " | |
rsync -az --exclude-from=$_FULL_DIR_PATH/.gitignore \ | |
--force --delete --rsh="ssh -p$REMOTE_PORT" \ | |
$_FULL_DIR_PATH/ $REMOTE_USER@$REMOTE_SERVER:$REMOTE_PROJECT_PATH | |
echo "### Cleaning up." | |
rm -rf $_FULL_DIR_PATH | |
echo "### Deployed successfully!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implementation: