-
-
Save ManukMinasyan/24f4f2240ebbc3e90149760a6aa82250 to your computer and use it in GitHub Desktop.
Laravel Forge zero downtime deployment script
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
| # stop script on error signal | |
| set -e | |
| SITE=${FORGE_SITE_PATH#"/home/forge/"} | |
| DEPL="/home/forge/deployments/${SITE}" | |
| # create directory and any intermediate directories if don't exist | |
| mkdir -p ${DEPL} | |
| CUR="/home/forge/${SITE}" | |
| NEW="${DEPL}/new" | |
| BKP="${DEPL}/backup" | |
| # remove old deployment folders | |
| if [ -d ${NEW} ]; then | |
| rm -R ${NEW} | |
| fi | |
| if [ -d ${BKP} ]; then | |
| rm -R ${BKP} | |
| fi | |
| cp -R ${CUR} ${NEW} | |
| cd ${NEW} | |
| ##################################################################### | |
| # Insert the rest of your standard Forge deployment script below here | |
| ##################################################################### | |
| # Pull the latest changes from the git repository | |
| # git reset --hard | |
| # git clean -df | |
| git pull origin $FORGE_SITE_BRANCH | |
| # Install/update composer dependecies | |
| composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev | |
| # Restart FPM | |
| ( flock -w 10 9 || exit 1 | |
| echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock | |
| # Run database migrations | |
| php artisan migrate --force | |
| # Install node modules | |
| npm ci | |
| # Build assets using Laravel Mix | |
| npm run build | |
| ##################################################################### | |
| # Your standard Forge deployment should end above | |
| ##################################################################### | |
| # Switch (downtime for microseconds) | |
| mv ${CUR} ${BKP} | |
| mv ${NEW} ${CUR} | |
| ##################################################################### | |
| # Cache clearing and caching | |
| ##################################################################### | |
| cd ${CUR} | |
| # Clear caches | |
| php artisan cache:clear | |
| # Clear expired password reset tokens | |
| php artisan auth:clear-resets | |
| # Clear and cache routes | |
| php artisan route:cache | |
| # Clear and cache config | |
| php artisan config:cache | |
| # Clear and cache views | |
| php artisan view:cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment