UI-UX/Dockerfile
zyc 7506372abd
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 5m45s
fix(ci): hoisted node_modules + alpine binary target for Prisma in Docker
Root cause (from build log):
1. Prisma 6 generates client into @prisma/client package dir (not .prisma/client)
2. pnpm default isolated linker puts everything in .pnpm/ store with symlinks
   at top-level — Docker COPY of @prisma followed broken/incomplete symlinks
3. node:22-alpine needs linux-musl-openssl-3.0.x engine binary

Fixes:
- .npmrc: node-linker=hoisted → flat node_modules, COPY behaves like npm
- schema.prisma: add linux-musl-openssl-3.0.x to binaryTargets
- Dockerfile: drop dead .prisma/client checks, copy only @prisma (where
  Prisma 6 actually writes the client) plus standalone output

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 14:13:37 +08:00

64 lines
2.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# syntax=docker/dockerfile:1
# ───────────── 1. deps安装依赖 + 显式生成 Prisma Client ─────────────
FROM node:22-alpine AS deps
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@latest --activate \
&& pnpm config set registry https://registry.npmmirror.com
# .npmrc 必须先 COPY否则 pnpm install 看不到 node-linker=hoisted
COPY .npmrc package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY prisma ./prisma
# pnpm 10+ 在 root/CI 默认跳过 lifecycle scripts因此显式调用 prisma generate
# Prisma 6 直接把 client 写入 @prisma/client 包目录(不再用 .prisma/client
RUN pnpm install --frozen-lockfile --ignore-scripts \
&& pnpm exec prisma generate \
&& ls -la /app/node_modules/@prisma/client/ \
&& ls /app/node_modules/@prisma/client/ | grep -E "(libquery_engine|schema.prisma|index.js)" || true
# ───────────── 2. builderNext.js 构建standalone 产物) ─────────────
FROM node:22-alpine AS builder
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@latest --activate
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
# COPY . . 会覆盖 prisma/schema 的最新版本,需要再 generate 一次确保 client 同步
RUN pnpm exec prisma generate \
&& pnpm exec next build \
&& ls -la /app/node_modules/@prisma/client/ \
&& ls -la /app/.next/standalone/
# ───────────── 3. runner最小运行时镜像 ─────────────
FROM node:22-alpine AS runner
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs
# Next.js standalone 自带通过 tracing 解析出的运行时依赖(含 @prisma/client
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
# 显式补 Prismatracing 有时会漏掉 engine 二进制和 schema
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]