Last active
May 23, 2020 12:20
-
-
Save ghostwriter/2c8539659727ab89162eb85c98b115a9 to your computer and use it in GitHub Desktop.
Deploy a Laravel app for free with GitHub Actions
This file contains hidden or 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: | |
| - uses: actions/checkout@v2 | |
| with: | |
| token: ${{ secrets.PUSH_TOKEN }} | |
| - name: Set up Node | |
| uses: actions/setup-node@v1 | |
| with: | |
| node-version: '12.x' | |
| - run: npm install | |
| - run: npm run production | |
| - name: Commit built assets | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git checkout -B deploy | |
| git add -f public/ | |
| git commit -m "Build front-end assets" | |
| git push -f origin deploy | |
| - name: Deploy to production | |
| uses: appleboy/ssh-action@master | |
| with: | |
| username: YOUR USERNAME GOES HERE | |
| host: YOUR SERVER'S HOSTNAME GOES HERE | |
| password: ${{ secrets.SSH_PASSWORD }} | |
| script: 'cd /var/www/html && ./server_deploy.sh' |
This file contains hidden or 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: CI | |
| on: [ push, pull_request ] | |
| jobs: | |
| tests: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Install dependencies | |
| run: composer install | |
| - name: Run tests | |
| run: vendor/bin/phpunit |
This file contains hidden or 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 hidden or 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 fetch origin deploy | |
| git reset --hard origin/deploy | |
| # 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!" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.gitignore, but are built on GitHubmasterbranch is used fordevelopmentproductionis pushed and deployeddeployis created by the Action, by taking production and adding a commit with the built assetsSo the code flows like this:
master-->production-->deploy.