Skip to content

Instantly share code, notes, and snippets.

@mydnic
Created January 30, 2020 10:22
Show Gist options
  • Save mydnic/d7baff0be20c5bc93b01a2b417156216 to your computer and use it in GitHub Desktop.
Save mydnic/d7baff0be20c5bc93b01a2b417156216 to your computer and use it in GitHub Desktop.
Zero Downtime deployment bash script
set -e
SITE="domain.com"
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}
# REGULAR SCRIPT
git reset --hard HEAD;git clean -df
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader
echo "" | sudo -S service php7.4-fpm reload
php artisan migrate --force
php artisan queue:restart
yarn
npm run prod
# /REUGLAR SCRIPT
# Switch (downtime for microseconds)
mv ${CUR} ${BKP}
mv ${NEW} ${CUR}
cd ${CUR}
php artisan cache:clear
php artisan config:clear
php artisan optimize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment