Skip to content

Instantly share code, notes, and snippets.

@npostman
Forked from BenSampo/deploy.sh
Last active July 17, 2022 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npostman/477319bb8b4108c29c655fef4c11ea6c to your computer and use it in GitHub Desktop.
Save npostman/477319bb8b4108c29c655fef4c11ea6c to your computer and use it in GitHub Desktop.
Laravel deploy script
# Change to the project directory
cd $FORGE_SITE_PATH
# Turn on maintenance mode
$FORGE_PHP artisan down --render='errors::503' --retry=30 || true
# Pull the latest changes from the git repository
# git reset --hard
# git clean -df
git pull origin $FORGE_SITE_BRANCH
# Install/update composer dependecies
$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader --no-dev
( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock
# Clear expired password reset tokens
#$FORGE_PHP artisan auth:clear-resets
# Clear and cache routes
$FORGE_PHP artisan route:cache
# Clear and cache config
$FORGE_PHP artisan config:cache
# Clear and cache views
$FORGE_PHP artisan view:cache
# Run database migrations
if [ -f artisan ]; then
$FORGE_PHP artisan migrate --force
fi
touch hash_resources.txt
HASH_RESOURCES="$(cat hash_resources.txt)"
find ./resources/sass ./resources/js ./webpack.mix.js ./package-lock.json -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum > hash_resources.txt
HASH_NEW_RESOURCES="$(cat hash_resources.txt)"
if [ "$HASH_RESOURCES" != "$HASH_NEW_RESOURCES" ]; then
echo "Running: npm"
npm ci
npm run prod
rm -rf node_modules
else
echo "Skipped: npm run prod"
fi
# Turn off maintenance mode
$FORGE_PHP artisan up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment