Files
zhangxiang d4caa7bef3 fix(deploy): 修复生产 CMS 解密失败与媒体库 500
- deploy.sh 构建时从 .env.production 显式注入 NEXT_PUBLIC_ENCRYPTION_SECRET,
  避免 .env.local 开发密钥覆盖生产密钥,导致前端 chunk 与后端 ENCRYPTION_SECRET
  不匹配,CMS 所有列表/仪表盘解密失败(The operation failed for an
  operation-specific reason)
- Dockerfile.prod 新增 sharp-deps 阶段,为 Alpine 容器补充 @img/sharp-linuxmusl-x64
  平台依赖,修复媒体库接口缺失 musl 二进制导致的 500
2026-08-20 12:06:34 +08:00

39 lines
1.3 KiB
Docker
Raw Permalink 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.
# ---------- sharp 平台依赖构建阶段 ----------
# 本地构建产物仅包含 darwin 平台二进制(@img/sharp-darwin-arm64),
# 容器运行于 Alpinelinuxmusl-x64),需补充 musl 平台二进制,否则媒体库接口报 500。
FROM node:20-alpine AS sharp-deps
WORKDIR /sharp
# 使用空 package.json,仅安装两个 musl 平台包,避免安装完整依赖树撑爆磁盘
RUN npm init -y >/dev/null 2>&1 && \
npm install --no-save --os=linux --cpu=x64 --libc=musl \
@img/sharp-linuxmusl-x64@0.35.3 \
@img/sharp-libvips-linuxmusl-x64@1.3.2
FROM node:20-alpine AS runner
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 16 standalone 输出:server.js 位于 dist/standalone 根目录
COPY dist/standalone ./
# 客户端静态资源(/_next/static
COPY dist/static ./dist/static
# 公共静态资源(图片、字体、favicon、uploads 等)
COPY public ./public
# 覆盖 sharp 平台依赖为 musl 版本(standalone 仅含 darwin 二进制)
COPY --from=sharp-deps /sharp/node_modules/@img /app/node_modules/@img
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]