Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy laravel application using github action

I am trying to deploy my laravel application to my server using Github actions for build and test and then deploy via ssh.

I have a master repository that I use for development and then I have a production repo that is attached to actions script.

I tried following this tutorial for github actions deployment.

My build works fine but at the time of deployment it is not able to find my deployment script i.e server_deploy.sh

here's my main.yml file

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 "[email protected]"
        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: ${{ secrets.SSH_USERNAME }}
        host: ${{ secrets.SSH_HOST }}
        password: ${{ secrets.SSH_PASSWORD }}
        script: 'cd /home/admin/web/case4.example.co/public_html/ && ls && sh server_deploy.sh'

and here's my server_deploy.sh

#!/bin/sh
set -e

echo "Deploying application ..."

# Enter maintenance mode
(php artisan down --message 'The app is being (quickly!) updated. Please try again in a minute.') || true
    # 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

# Exit maintenance mode
php artisan up

echo "Application deployed!"

However, when I execute this workflow, it cannot find the server_deploy.sh file. Deployment error

I tried ls to see if even my repo checks out but it doesn't.

Please help.

like image 643
Pankaj Jha Avatar asked Jun 28 '26 04:06

Pankaj Jha


1 Answers

You didn't setup your server according to the tutorial

Note that the server is always on the deploy branch.

With all this set up, install your Laravel application into /var/www/html and checkout the deploy branch. If it doesn’t exist yet, you can do git checkout production && git checkout -b deploy to create it.

You have to run this once on your server and checkout the deploy branch that contains the deploy script server_deploy.sh

like image 71
riQQ Avatar answered Jun 30 '26 18:06

riQQ