Last active
August 29, 2015 14:06
-
-
Save gravitano/966e4f84fa057f8e7991 to your computer and use it in GitHub Desktop.
Git hook
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 | |
| # | |
| ## 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/ | |
| # The composer directory | |
| COMPOSERDIR=composer | |
| # Repository Directory | |
| REPODIR=$HOME/repo.git | |
| ## 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 | |
| ## Down | |
| php $DEPLOYDIR/artisan down | |
| ## Update the deployed copy | |
| echo "Starting Deploy" >> $LOGFILE | |
| echo "- Deploying" | |
| GIT_WORK_TREE="$DEPLOYDIR" git checkout -f | |
| echo "- OK" | |
| echo "- Composer Hook : Updating Dependencies" | |
| cd $DEPLOYDIR && $COMPOSERDIR update | |
| echo "- OK" | |
| echo "Updating folder permission" | |
| chown -R root:www-data $DEPLOYDIR | |
| chmod -R 0775 $DEPLOYDIR | |
| echo "- OK" | |
| ## Live | |
| php $DEPLOYDIR/artisan up | |
| echo "- Done" | |
| echo "Finished Deploy" >> $LOGFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup git:
Setup hook:
cd repo.git/hooks wget https://gist.github.com/gravitano/966e4f84fa057f8e7991/raw/27919e720fdb715a40906ebcbd220272324f305e/post-receive.sh mv post-receive.sh post-receive chmod +x post-receive