[GITHUB] CI CD Backend Laravel using ssh action - fourslickz/notes GitHub Wiki
FIRST THING TODO:
- SERVER PRODUCTION
- git clone -b {development-branch} {github-repository}
- composer install
- cp .env.production .env
- php artisan key:generate
- chmod -R 777 storage bootstrap/cache
-
github account setting add ssh-key from server production / development
-
repo setting
- {SSH_PRIVATE_KEY_PRODUCTION}
- {SSH_USERNAME_PRODUCTION}
- {SSH_HOST_PRODUCTION}
-
setup workflow
name: Laravel CI/CD
on:
push:
branches: [ "main", "development" ]
pull_request:
branches: [ "main", "development" ]
jobs:
laravel-tests:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '7.4'
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install --ignore-platform-req=ext-grpc
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
deploy-production:
name: Deploy Project to Production Server
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '7.4'
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install --ignore-platform-req=ext-grpc
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
- name: Deploy using ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST_PRODUCTION }}
username: ${{ secrets.SSH_USERNAME_PRODUCTION }}
key: ${{ secrets.SSH_PRIVATE_KEY_PRODUCTION }}
port: 22
script_stop: true
script: |
cd ~/apps/project-directory
git pull origin main
git status
composer install
cp .env.production .env
php artisan key:generate