diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1a21040 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,27 @@ +name: Deploy + +# Trigger the workflow on push and +# pull request events on the production branch +on: + push: + branches: + - production + pull_request: + branches: + - production + +# Authenticate to the the server via ssh +# and run our deployment script +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Deploy to server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + port: ${{ secrets.PORT }} + key: ${{ secrets.SSHKEY }} + script: "cd /home/UpdateServer/web/update.techscode.com/public_html/ && deploy.sh" diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..bca07b9 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +echo "Deployment started ..." + +# Enter maintenance mode or return true +# if already is in maintenance mode +(php artisan down) || true + +# Pull the latest version of the app +git pull origin production + +# Install composer dependencies +composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader + +# Clear the old cache +php artisan clear-compiled + +# Recreate cache +php artisan optimize + +# Compile npm assets +npm run prod + +# Run database migrations +php artisan migrate --force + +# Exit maintenance mode +php artisan up + +echo "Deployment finished!"