Last active
May 7, 2024 17:31
-
-
Save JoeCrescoll/c1930cbeecc8811b4c8ba34e6f127b8b to your computer and use it in GitHub Desktop.
Post receive hook on a Git bare repo for a Laravel project deploy
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 | |
# Adapted from https://gist.github.com/noelboss/3fe13927025b89757f8fb12e9066f2fa | |
# Changes these variables values | |
TARGET="/home/poweruser/www/app" | |
GIT_DIR="/home/poweruser/menufinder.git" | |
BRANCH="master" | |
while read oldrev newrev ref | |
do | |
# only checking out the master (or whatever branch you would like to deploy) | |
if [[ $ref = refs/heads/$BRANCH ]]; | |
then | |
echo "Ref $ref received. Deploying ${BRANCH} branch to production..." | |
# Puts the Laravel application into maintenance mode | |
php ${TARGET}/artisan down 2> /dev/null | |
# Updates the application (work tree) with the latest changes | |
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f | |
# Updates composer and npm packages | |
composer install -d $TARGET --no-progress --no-interaction --prefer-dist --no-suggest --no-dev | |
npm --prefix $TARGET install $TARGET --only=prod | |
# Builds frontend assets | |
npm --prefix $TARGET run prod | |
# Brings the Laravel application out of maintenance mode | |
php ${TARGET}/artisan up 2> /dev/null | |
else | |
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment