Skip to content

Instantly share code, notes, and snippets.

@klang
Created March 25, 2014 07:32
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 klang/9756765 to your computer and use it in GitHub Desktop.
Save klang/9756765 to your computer and use it in GitHub Desktop.
hook to automatically deploy an app, when pushes to a repository is made. The script has to be placed in .git/hooks/post-receive and made executable. Script taken from: http://www.sitepoint.com/one-click-app-deployment-server-side-git-hooks/
#!/bin/sh
# blog post: http://www.sitepoint.com/one-click-app-deployment-server-side-git-hooks/
## store the arguments given to the script
read oldrev newrev refname
## Where to store the log information about the updates
LOGFILE=./post-receive.log
# The deployed directory (the running site)
DEPLOYDIR=/var/www/html/simpleapp
DEPLOYDIR=/Users/klp/projects/Versioning/examples/git-one-click-deployment/production/simpleapp
## Record the fact that the push has been received
echo -e "Received Push Request at $( date +%F )" >> $LOGFILE
echo " - Old SHA: $oldrev New SHA: $newrev Branch Name: $refname" >> $LOGFILE
## Update the deployed copy
echo "Starting Deploy" >> $LOGFILE
echo " - Starting code update"
GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
echo " - Finished code update"
echo " - Starting post deployment work"
cd "$DEPLOYDIR"; echo "dot the i's and slash the t's"; cd -
echo " - Finished post deployment work"
echo "Finished Deploy" >> $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment