Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ashupp/dcffda3082309d73e307606332014a91 to your computer and use it in GitHub Desktop.
Save ashupp/dcffda3082309d73e307606332014a91 to your computer and use it in GitHub Desktop.
Example of how to gracefully deploy a new release when using Envoyer. Optionally, you could just stop/resume only the Horizon daemons, but since we only have one Supervisor daemon, this works fine.
# After *Activate New Release*
cd {{ release }}
php artisan cache:clear
php artisan view:clear
php artisan purifier:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Restart all queue workers
# Requires passwordless sudo permissions!
sudo supervisorctl start all \
&& echo 'Supervisor jobs resumed!' \
|| echo 'Failed to restart Supervisor jobs'
# Write git hash to file for Sentry
echo "{{ sha }}" > {{ release }}/.commit_hash
# Tag a release for Sentry
curl --silent --show-error https://sentry.io/api/hooks/release/builtin/:projectId/:webhook/ \
-X POST -H 'Content-Type: application/json' -d '{"version": "{{ sha }}"}'
# After *Install Composer Dependencies*
cd {{ release }}
# Stop all queue workers
# Requires passwordless sudo permissions!
sudo supervisorctl stop all
# Stop Horizon during this deploy
php artisan horizon:purge
php artisan horizon:terminate
# Symlink local public storage directory
php artisan storage:link
# Install and build front-end assets
yarn install --non-interactive
yarn run production
# Migrate database structure
php artisan migrate --force
# Seed data
php artisan db:seed --class="ProductionSeeder" --force

Envoyer deploy hooks require passwordless sudo supervisorctl process stop/start permissions. Make sure /etc/sudoers.d/supervisorctl exists and contains:

forge ALL=NOPASSWD: /usr/bin/supervisorctl status
forge ALL=NOPASSWD: /usr/bin/supervisorctl start all
forge ALL=NOPASSWD: /usr/bin/supervisorctl stop all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment