Last active
September 16, 2024 02:39
-
-
Save stancl/cab04a411f136047e80c1de81528eb23 to your computer and use it in GitHub Desktop.
Deploy using GitHub actions and SSH to a VPS
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
#!/bin/sh | |
set -e | |
vendor/bin/phpunit | |
npm run prod | |
git add . | |
(git commit -m "Build frontend assets for deployment to production") || true | |
(git push) || true | |
git checkout production | |
git merge master | |
git push origin production | |
git checkout master |
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
name: CD | |
on: | |
push: | |
branches: [ production ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to <your domain> | |
uses: appleboy/ssh-action@master | |
with: | |
username: <your username> | |
host: <your domain> | |
password: ${{ secrets.SSH_PASSWORD }} | |
script: 'cd /var/www/html && ./server_deploy.sh' |
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
#!/bin/bash | |
set -e | |
echo "Deploying application ..." | |
# Enter maintanance mode | |
php artisan down | |
# Update codebase | |
git pull origin production | |
# Install dependencies based on lock file | |
composer install --no-interaction --prefer-dist --optimize-autoloader | |
# Migrate database | |
php artisan migrate --force | |
# Clear cache | |
php artisan optimize | |
# Reload PHP to update opcache | |
echo "" | sudo -S service php7.4-fpm reload | |
# Exit maintenance mode | |
php artisan up | |
echo "🚀 Application deployed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment