-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
50 lines (43 loc) · 1.76 KB
/
Copy pathDockerfile
File metadata and controls
50 lines (43 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Stage 1: Base image
FROM node:22-alpine AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate
# Stage 2: Install dependencies
FROM base AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
# Use a cache mount for the pnpm store and configure pnpm to copy packages (avoid EXDEV errors)
# Skip running lifecycle scripts during install as config files might be missing
RUN --mount=type=cache,mode=0777,id=pnpm,target=/pnpm/store \
pnpm config set store-dir /pnpm/store && \
pnpm config set package-import-method copy && \
pnpm install --frozen-lockfile --ignore-scripts
# Stage 3: Build the application
FROM base AS builder
WORKDIR /app
# Bring in installed node_modules from the deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy all source files
COPY . .
# Set production mode for the build
ENV NODE_ENV=production
# Ensure the Next.js cache directory exists and has proper permissions
RUN mkdir -p /app/.next/cache && chown -R node:node /app/.next/cache
# Use a cache mount for Next.js cache to speed up rebuilds
RUN --mount=type=cache,mode=0777,id=nextjs-cache,target=/app/.next/cache \
pnpm run build
# Stage 4: Production server
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Copy only the necessary artifacts from the builder stage
# Copy the main standalone server files and dependencies
COPY --from=builder /app/.next/standalone ./
# Copy static assets generated by the build
COPY --from=builder /app/.next/static ./.next/static
# Copy public assets. In standalone mode, Next.js copies the project's
# public directory into .next/standalone/public during the build.
# COPY --from=builder /app/.next/standalone/public ./public
EXPOSE 3000
CMD ["node", "server.js"]