Next.js Discord

Discord Forum

CI/CD with GitHub Actions & Standalone app

Citrine Wagtail posted this in #help-forum
Open in Discord
Citrine WagtailOP
I've got a GitHub Actions pipeline setup that builds a Docker image (for linux/arm64), deploys on GitHub Container Registry, then SSHs on the VPS and pulls the latest image. The deployment step approximately 7 minutes, and the deployment finishes in around 20 seconds.

I am thinking my problem is that I am building for linux/arm64, although I really don't have any alternatives - since that's the server architecture.

Here's the build part of the workflow:

    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Publish to Registry
        uses: elgohr/Publish-Docker-Github-Action@v5
          name: user/project/image
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets. GITHUB_TOKEN }}
          dockerfile: Dockerfile
          platforms: linux/arm64
          tags: latest

7 minutes is taken by elgohr/Publish-Docker-Github-Action@v5, although there aren't any obvious errors. Are there any alternatives that could speed up my deployment process?

The RUN npm ci step is taking 100 seconds, RUN npx prisma generate takes 25 seconds, npm run build takes 263 seconds. Is this normal? Is my Dockerfile wrong? Is it normal for NextJS to take so long to create a build (for a small, hello world app)?

2 Replies

Citrine WagtailOP
Here's my Dockerfile

FROM node:20-alpine AS deps

RUN apk update && apk add --no-cache libc6-compat && apk add git

COPY package.json package-lock.json ./
RUN npm ci

# Rebuild the source code only when needed
FROM node:20-alpine AS builder
COPY . .
COPY --from=deps /app/node_modules ./node_modules
ARG NODE_ENV=production
RUN echo ${NODE_ENV}
RUN npx prisma generate
RUN npm run build

FROM node:20-alpine AS runner
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

#copy next config js if not using default config
COPY --from=builder /app/next.config.js ./next.config.js
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

COPY --chown=nextjs:nodejs prisma ./prisma/
COPY --chown=nextjs:nodejs ./

RUN apk add --no-cache ca-certificates openssl bash

RUN chmod +x

USER nextjs
CMD ["./"] contains
# Run migrations
DATABASE_URL="file:./dev.db" npx --yes prisma migrate deploy
# start app
DATABASE_URL="file:./dev.db" node server.js

so nothing special.
Build command runs: next build