47 lines
1.1 KiB
Docker
47 lines
1.1 KiB
Docker
# 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 fetch
|
|
|
|
# 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 chmod +x ./scripts/*.sh && ./scripts/first_page_image.sh
|
|
|
|
# Run the build.
|
|
RUN pnpm build
|
|
|
|
# Stage 3: Runner
|
|
FROM node:20-alpine AS runner
|
|
WORKDIR /app
|
|
|
|
# Create a non-root user for better security
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
USER nextjs
|
|
|
|
# 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
|
|
|
|
# The standalone output creates a server.js file that is the entrypoint
|
|
CMD ["node", "server.js"] |