mirror of
https://github.com/civitai/civitai.git
synced 2026-09-20 22:08:18 +08:00
d9e2269bd9
node:20-alpine3.16 is a frozen tag — Alpine 3.16 went EOL in May 2024
and Docker Hub stopped publishing newer Node 20 builds against it,
locking the runtime at Node 20.2.0 (May 2023).
The stale Node ABI and old musl 1.2.3 are the most likely cause of the
recurring SIGSEGV (exitCode=139) crashes seen on civitai-dp-prod SSR
pods — ~50/day across all SSR-eligible nodes. The Prisma 6.13 native
musl engine was published ~14 months after this Node build, exactly
the skew that produces native segfaults on edge cases like a Postgres
connection closing mid-query (the chronic "Error { kind: Closed }"
pattern in our logs).
alpine3.20 ships current Node 20.18+, current openssl 3.0.13, and
musl 1.2.5. Same major Node, same package manager, same build steps —
no application changes required.
70 lines
2.0 KiB
Docker
70 lines
2.0 KiB
Docker
##### DEPENDENCIES
|
|
|
|
FROM node:20-alpine3.20 AS deps
|
|
RUN apk add --no-cache libc6-compat
|
|
WORKDIR /app
|
|
|
|
# Enable corepack for pnpm
|
|
RUN corepack enable && corepack prepare pnpm@10.28.1 --activate
|
|
|
|
# Copy Prisma schema for client generation (postinstall generates schema.prisma from this)
|
|
COPY prisma/schema.full.prisma ./prisma/
|
|
|
|
# Install dependencies — lockfile and scripts rarely change, so they go first.
|
|
# package.json changes on every version bump but pnpm only needs it for the
|
|
# workspace root name; the store cache mount lets pnpm reuse downloaded packages
|
|
# even when this layer is invalidated.
|
|
COPY pnpm-lock.yaml package.json ./
|
|
COPY scripts ./scripts
|
|
COPY patches ./patches
|
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
pnpm install --frozen-lockfile
|
|
|
|
##### BUILDER
|
|
|
|
FROM node:20-alpine3.20 AS builder
|
|
ARG NEXT_PUBLIC_IMAGE_LOCATION
|
|
ARG NEXT_PUBLIC_CONTENT_DECTECTION_LOCATION
|
|
ARG NEXT_PUBLIC_MAINTENANCE_MODE
|
|
WORKDIR /app
|
|
|
|
# Enable corepack for pnpm
|
|
RUN corepack enable && corepack prepare pnpm@10.28.1 --activate
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
COPY . .
|
|
# Restore generated schema.prisma from deps (COPY . . overwrites it with source which doesn't have it)
|
|
COPY --from=deps /app/prisma/schema.prisma ./prisma/schema.prisma
|
|
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
RUN --mount=type=cache,target=/app/.next/cache \
|
|
SKIP_ENV_VALIDATION=1 IS_BUILD=true NODE_OPTIONS="--max_old_space_size=6144" pnpm run build
|
|
|
|
##### RUNNER
|
|
|
|
FROM node:20-alpine3.20 AS runner
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
# ENV NEXT_TELEMETRY_DISABLED 1
|
|
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
COPY --from=builder /app/next.config.mjs ./
|
|
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
|
|
|
|
USER nextjs
|
|
EXPOSE 3000
|
|
ENV PORT=3000
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
CMD ["node", "--", "server.js", "--", "--expose-gc"]
|