Skip to content

Instantly share code, notes, and snippets.

@psaia
Last active August 29, 2015 14:00
Show Gist options
  • Save psaia/11226368 to your computer and use it in GitHub Desktop.
Save psaia/11226368 to your computer and use it in GitHub Desktop.
########################################
# 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
@psaia
Copy link
Author

psaia commented Apr 23, 2014

Implementation:

########################################
# File: /some/repo/hooks/post-receive
########################################

#!/bin/bash
read oldrev newrev refname

deploy staging /var/www/my-project/staging/ 198.101.153.95 22 dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment