Next.js Discord

Discord Forum

Github Actions deployment

Answered
Citrine Wagtail posted this in #help-forum
Open in Discord
Citrine WagtailOP
I've set up a github action to deploy via SSH to our server. It seems to run very slow - indeed it's the first run, but it's been 10 minutes.
The app is currently the barebones next project.

name: Build and Deploy

on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
        - name: Checkout Main Branch
          uses: actions/checkout@v2
          with:
            fetch-depth: 0
            ref: main

        - name: Use Node.js
          uses: actions/setup-node@v1
          with:
            node-version: "16.x"

        - name: Install Dependencies
          run: npm install

        - name: Build Application
          run: npm run build

        - name: Install SSH Key
          uses: shimataro/ssh-key-action@v2
          with:
            key: ${{ secrets.SSH_PRIVATE_KEY }}
            known_hosts: unnecessary
            
        - name: Adding Known Hosts
          run: |
            mkdir -p ~/.ssh
            touch ~/.ssh/authorized_keys
            ssh-keyscan -H ${{ secrets.SSH_HOST }}  >> ~/.ssh/known_hosts
            
        - name: Deploy with rsync
          run: rsync -avz . ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:${{ secrets.TARGET_DIRECTORY }}
Answered by Citrine Wagtail
Okay, I'll try the standalone mode now.
Found that here: https://nextjs.org/docs/app/api-reference/next-config-js/output
View full answer

9 Replies

Giant panda
Because you probably are syncing the entire repository and the million node_modules etc.
When building the app you only need the .next folder
Check the docs for more details on self-hosting
Citrine WagtailOP
So on production I don't need the node_modules, even if I use SSR?
Thanks!
@Giant panda Check the docs for more details on self-hosting
Citrine WagtailOP
I've been looking at this, but I can't find anything specific regarding this in the docs.

https://stackoverflow.com/a/65267558/7120166
Citrine WagtailOP
Okay, I'll try the standalone mode now.
Found that here: https://nextjs.org/docs/app/api-reference/next-config-js/output
Answer
Citrine WagtailOP
Seems to have synced correctly now.