Last active
October 13, 2018 10:30
-
-
Save CharlieEtienne/d83518862353d88e7552db895394e2bb to your computer and use it in GitHub Desktop.
Git hook "post-update" located in "/home/username/.git/hooks/"
This file contains 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/bash | |
# | |
# Hook script to pull automatically | |
# stage branch in /stage folder and master branch in /prod folder | |
# when a push is detected | |
# Replace "username" by your username | |
ME="username" | |
# Determining which branch was pushed | |
if ! [ -t 0 ]; then | |
read -a ref | |
fi | |
IFS='/' read -ra REF <<< "${ref[2]}" | |
branch="${REF[2]}" | |
echo "Branch pushed: $branch" | |
# If it was 'stage' branch | |
if [ "stage" == "$branch" ]; then | |
echo "#######################################################" | |
echo "#################### STAGE DEPLOY #####################" | |
echo "#######################################################" | |
# Go to site directory | |
cd /home/${ME}/www/stage | |
echo "*******************************************************" | |
# Shutdown the laravel app | |
/usr/local/php7.2/bin/php artisan down | |
echo "*******************************************************" | |
# Pull changes from git dir | |
unset GIT_DIR | |
git fetch origin stage | |
git reset --hard FETCH_HEAD | |
echo "*******************************************************" | |
# Install new composer packages | |
/usr/local/php7.2/bin/php ~/composer.phar install | |
echo "*******************************************************" | |
# Clear caches | |
/usr/local/php7.2/bin/php artisan cache:clear | |
echo "*******************************************************" | |
# Clear expired password reset tokens | |
/usr/local/php7.2/bin/php artisan auth:clear-resets | |
echo "*******************************************************" | |
# Clear and cache routes | |
/usr/local/php7.2/bin/php artisan route:clear | |
/usr/local/php7.2/bin/php artisan route:cache | |
echo "*******************************************************" | |
# Clear and cache config | |
/usr/local/php7.2/bin/php artisan config:clear | |
/usr/local/php7.2/bin/php artisan config:cache | |
echo "*******************************************************" | |
# Go live ! | |
/usr/local/php7.2/bin/php artisan up | |
echo "#######################################################" | |
echo "###################### DEPLOYED! ######################" | |
echo "#######################################################" | |
# If it was 'master' branch | |
elif [ "master" == "$branch" ]; then | |
echo "#######################################################" | |
echo "##################### PROD DEPLOY #####################" | |
echo "#######################################################" | |
# Go to site directory | |
cd /home/${ME}/www/prod | |
echo "*******************************************************" | |
# Shutdown the laravel app | |
/usr/local/php7.2/bin/php artisan down | |
echo "*******************************************************" | |
# Pull changes from git dir | |
unset GIT_DIR | |
git fetch origin master | |
git reset --hard FETCH_HEAD | |
echo "*******************************************************" | |
# Install new composer packages | |
/usr/local/php7.2/bin/php ~/composer.phar install --no-dev --prefer-dist --optimize-autoloader | |
echo "*******************************************************" | |
# Clear caches | |
/usr/local/php7.2/bin/php artisan cache:clear | |
echo "*******************************************************" | |
# Clear expired password reset tokens | |
/usr/local/php7.2/bin/php artisan auth:clear-resets | |
echo "*******************************************************" | |
# Clear and cache routes | |
/usr/local/php7.2/bin/php artisan route:clear | |
/usr/local/php7.2/bin/php artisan route:cache | |
echo "*******************************************************" | |
# Clear and cache config | |
/usr/local/php7.2/bin/php artisan config:clear | |
/usr/local/php7.2/bin/php artisan config:cache | |
echo "*******************************************************" | |
# Go live ! | |
/usr/local/php7.2/bin/php artisan up | |
echo "#######################################################" | |
echo "###################### DEPLOYED! ######################" | |
echo "#######################################################" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment