Skip to content

Instantly share code, notes, and snippets.

@zacksmash
Last active January 13, 2024 18:32
Show Gist options
  • Save zacksmash/ed68152cef6c0066a2990f0cb8c4403f to your computer and use it in GitHub Desktop.
Save zacksmash/ed68152cef6c0066a2990f0cb8c4403f to your computer and use it in GitHub Desktop.
Laravel Forge Zero Downtime Script
# Stop On Error
set -e
# Set Paths
SITE=${FORGE_SITE_PATH#"/home/forge/"}
DEPL="/home/forge/deployments/${SITE}"
# Create Deployment Directory
mkdir -p ${DEPL}
CUR=$FORGE_SITE_PATH
NEW="${DEPL}/new"
BKP="${DEPL}/backup"
# Remove Old Deployments
if [ -d ${NEW} ]; then
rm -Rf ${NEW}
fi
if [ -d ${BKP} ]; then
rm -Rf ${BKP}
fi
rsync -rtv ${CUR}/ ${NEW}/
cd ${NEW}
####
# DEPLOY SCRIPT
####
git pull origin $FORGE_SITE_BRANCH
$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader
( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock
$FORGE_PHP artisan migrate --force
$FORGE_PHP artisan auth:clear-resets
$FORGE_PHP artisan config:cache
$FORGE_PHP artisan route:cache
$FORGE_PHP artisan view:cache
npm ci
npm run production
rm -rf node_modules
####
# /DEPLOY SCRIPT
####
# Switch To Current Deployment
rsync -rtv ${CUR}/ ${BKP}/
rsync -rtv ${NEW}/ ${CUR}/
# Finish up in site directory
cd $FORGE_SITE_PATH
$FORGE_PHP artisan cache:clear
# If using Horizon
$FORGE_PHP artisan horizon:terminate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment