Restructure Dockerfile based on pnpm docs
Some checks failed
Next.js App CI / docker (push) Failing after 45s
Some checks failed
Next.js App CI / docker (push) Failing after 45s
This commit is contained in:
54
Dockerfile
54
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
|
||||
|
||||
Reference in New Issue
Block a user