Skip to content

Instantly share code, notes, and snippets.

@vamuigua
Forked from stancl/deploy.sh
Created May 25, 2022 20:34
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 vamuigua/f861be7f3562592348c8edb5163b9367 to your computer and use it in GitHub Desktop.
Save vamuigua/f861be7f3562592348c8edb5163b9367 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