From 756e6eec82c3145096addfd2fc3fe767f9a259f2 Mon Sep 17 00:00:00 2001 From: Steffen Illium Date: Mon, 15 Sep 2025 15:43:15 +0200 Subject: [PATCH] Restructure Dockerfile based on pnpm docs --- Dockerfile | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0fe0a7b4..bb47f57c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,46 +1,44 @@ -# Stage 1: Builder -FROM node:20-alpine AS builder - -# Install system dependencies for image manipulation (ImageMagick v7+) -RUN apk add --no-cache imagemagick libwebp libwebp-tools ghostscript - -# Enable pnpm -RUN corepack enable - -# WORKDIR /app - -# Copy dependency files and install dependencies -# This is cached separately from the source code +# Stage 1: Dependency Fetching +FROM node:20-alpine AS deps +WORKDIR /app +RUN npm i -g pnpm COPY package.json pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile +RUN pnpm fetch -# Copy the rest of the application source code +# Stage 2: Builder +FROM node:20-alpine AS builder +WORKDIR /app +RUN npm i -g pnpm + +# Install system dependencies +RUN apk add --no-cache imagemagick ghostscript + +# Copy the dependency manifests and then run install. +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile --offline + +# Copy the rest COPY . . # --- Asset Generation Step --- -RUN ls -la . -RUN ls -la /scripts RUN chmod +x ./scripts/*.sh && ./scripts/first_page_image.sh -# Run the build command +# Run the build. RUN pnpm build -# --- - -# Stage 2: Runner +# Stage 3: Runner FROM node:20-alpine AS runner -# WORKDIR /app +WORKDIR /app -# Create a non-root user for security +# Create a non-root user for better security RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs USER nextjs -# Copy the standalone output from the builder stage -# The './public' directory now contains the newly generated assets -COPY --from=builder /public ./public -COPY --from=builder --chown=nextjs:nodejs .next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs .next/static ./.next/static +# Copy only the necessary production artifacts from the builder stage +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static EXPOSE 3000 ENV PORT=3000