Skip to content

Instantly share code, notes, and snippets.

@twhite96
Forked from stancl/deploy.sh
Created September 16, 2024 02:39
Show Gist options
  • Save twhite96/0d6bfc4548faa1b89b610459ba2d08f6 to your computer and use it in GitHub Desktop.
Save twhite96/0d6bfc4548faa1b89b610459ba2d08f6 to your computer and use it in GitHub Desktop.
Deploy using GitHub actions and SSH to a VPS
#!/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
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'
#!/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