Last active
May 23, 2021 05:18
-
-
Save junkystu/27b25d5b54225812f95d to your computer and use it in GitHub Desktop.
Script for quicker deployment with Laravel and Forge
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
# The idea of this deployment script is to create a deploy copy of your website and handle | |
# Git and Composer updates in there. Aferwards, it just renames that deploy copy to become the | |
# live website. We then run the database migrations and take the application out of maintenance mode. | |
# Obviously, you will have to replace all instances of {{ websiteName }} with the name of your website and | |
# {{ branchName }} with the name of the branch you would like to pull changes from. This is usually the master branch. | |
# Start by checking for for old deployment folder and remove it if we have one. | |
if [ -d "/home/forge/{{ websiteName }}-deploy" ]; then | |
rm -Rf /home/forge/{{ websiteName }}-deploy | |
fi | |
# Check for old backup folder and remove that too. | |
if [ -d "/home/forge/{{ websiteName }}-backup" ]; then | |
rm -Rf /home/forge/{{ websiteName }}-backup | |
fi | |
# Make a copy of the current website and suffix it with -deploy. | |
cp -R /home/forge/{{ websiteName }} /home/forge/{{ websiteName }}-deploy | |
# Navigate to the folder where we'll handle the deployment. | |
cd /home/forge/{{ websiteName }}-deploy | |
# Pull new changes from Git repository. | |
git pull origin {{ branchName }} | |
# Update / install Composer dependencies | |
composer install --no-interaction --no-dev --prefer-dist | |
# Put the deployment app in maintenance mode. | |
php artisan down | |
# Move the current website to a backup folder. | |
mv /home/forge/{{ websiteName }} /home/forge/{{ websiteName }}-backup | |
# Rename the recently updated deploy copy to become the live website. | |
mv /home/forge/{{ websiteName }}-deploy /home/forge/{{ websiteName }} | |
# Navigate to current live website which is now in maintenance mode. | |
cd /home/forge/{{ websiteName }} | |
# Update database. | |
php artisan migrate --force | |
# Update route caching (Optional). | |
php artisan route:cache | |
# Lastly, take the app out of maintenance mode. | |
php artisan up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment