Next.js Discord

Discord Forum

Need help in configuring github actions to deploy a next app in different server.

Unanswered
Tan posted this in #help-forum
Open in Discord
TanOP
Hi guys,
I was trying to deploy a nextjs application on a diffrent server. I could do it manually. But I was just curious about github actions and found it really great. I tried to create a workflow. It works but I am not able to sync the build files with my server.

Basically how I used to deploy step by step:
1. First I would push the changes in github and build it on my local machine.
2. Second I would rsync to sync my local build files to the server like this : rsync -avz -e ssh .next <USER_NAME>@<SERVER_IP>:/home6/<USER_NAME>/<MY_COOL_PROJECT>/
3. Then I would touch the MY_COOL_PROJECT/tmp/restart.txt file to restart the server. I was using a service that uses cpanel to manage the applications.

So this was my manual deployment process. I digged little bit about github actios and wanted to automate my task. I have wrote a functional yaml file but when it comes to syncing the build files I am not able to do it.

Here is my yaml configuration :

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Install dependencies
        run: npm install --force

      - name: Build Next.js application
        run: npm run build

      - name: Sync .next folder with server
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.SERVER_HOST }}
          username: ${{ secrets.SERVER_USERNAME }}
          password: ${{ secrets.SERVER_PASSWORD }}
          script: |
            exec ~/MY_COOL_PROJECT/scripts/deploy &
            rsync -avz  $GITHUB_WORKSPACE/.next ~/MY_COOL_PROJECT/.next &
            touch ~/MY_COOL_PROJECT/tmp/restart.txt

Why is it not syncing any idea ?

0 Replies