Files
writer-work-flow/apps/web/Dockerfile

39 lines
2.4 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.

FROM node:22-slim AS build
WORKDIR /app
# npm/corepack registry可经 build arg 覆盖):部分区域 registry.npmjs.org 不可达,部署时指向镜像
# (如 registry.npmmirror.com整源镜像 npmjs 且保留 integrity与 --frozen-lockfile 兼容)。
ARG NPM_REGISTRY=https://registry.npmjs.org
ENV npm_config_registry=$NPM_REGISTRY
# corepack 默认硬编码从 npmjs 下载 pnpm 本体;此处改指同一镜像。镜像不提供 npm 签名密钥,
# 关掉签名校验(下载的 pnpm tarball 仍按内容哈希校验,安装的依赖仍按 lockfile integrity 校验)。
ENV COREPACK_NPM_REGISTRY=$NPM_REGISTRY
ENV COREPACK_INTEGRITY_KEYS=0
RUN corepack enable
# pnpm-workspace.yaml 必须在 install 前就位:它携带 minimumReleaseAgeExclude豁免新发布包的
# 供应链策略、onlyBuiltDependencies/allowBuilds构建脚本白名单。缺它则容器内 install 看不到
# 这些策略,会误拒近期发布的依赖(如 @xyflow/*)而失败——与宿主行为不一致。
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml ./
# pnpm 11 不读 npm_config_registry env须用 --registry 显式指定镜像lockfile v9 仅存 integrity
# 不含绝对 URL故换源不破坏 --frozen-lockfile
RUN pnpm install --frozen-lockfile --registry="$NPM_REGISTRY" || pnpm install --registry="$NPM_REGISTRY"
COPY . .
# NEXT_PUBLIC_* 在 Next 构建期内联进浏览器 bundle——必须在 `pnpm build` 前用 build ARG 注入。
# 默认 http://localhost:8000 供 dev生产经 compose build args 传公网 API 基址。
ARG NEXT_PUBLIC_API_BASE=http://localhost:8000
ENV NEXT_PUBLIC_API_BASE=$NEXT_PUBLIC_API_BASE
RUN pnpm build
# 本项目 public/ 为空目录(不入 gitgit archive 构建上下文里不存在);确保它存在,
# 否则下方 run 阶段 `COPY --from=build /app/public` 会因源缺失而失败。
RUN mkdir -p /app/public
FROM node:22-slim AS run
WORKDIR /app
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
EXPOSE 3000
# 存活探测node 打首页run 阶段无 curl5xx/连接失败退出非零。
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD ["node", "-e", "require('http').get('http://127.0.0.1:3000/',r=>process.exit(r.statusCode<500?0:1)).on('error',()=>process.exit(1))"]
CMD ["node", "server.js"]