# Build stage FROM git.xiaoxiajianji.com/xiaoxia/base/node:20 AS builder WORKDIR /app ARG VITE_API_URL=https://saas-api.xiaoxiajianji.com ENV VITE_API_URL=$VITE_API_URL # 先拷依赖清单(缓存友好:依赖不变时直接命中缓存层) COPY apps/web/package.json apps/web/package-lock.json ./apps/web/ WORKDIR /app/apps/web # 安装依赖:用BuildKit cache mount缓存npm下载和node_modules # sharing=locked 防止并发构建竞争写缓存 RUN --mount=type=cache,target=/root/.npm,sharing=locked \ --mount=type=cache,target=/app/apps/web/node_modules,sharing=locked \ npm config set registry https://registry.npmmirror.com \ && npm ci # 再拷源码 COPY apps/web/ ./ # 构建:TS增量编译 + Vite构建,tsbuildinfo用cache mount持久化 RUN --mount=type=cache,target=/app/apps/web/node_modules,sharing=locked \ --mount=type=cache,target=/app/apps/web/.tscache,sharing=locked \ mkdir -p .tscache \ && npx tsc --incremental --tsBuildInfoFile .tscache/tsconfig.tsbuildinfo \ && npx vite build # Production stage with nginx FROM git.xiaoxiajianji.com/xiaoxia/base/nginx:alpine AS runner ARG NGINX_CONF=infra/docker/nginx.conf WORKDIR /usr/share/nginx/html COPY --from=builder /app/apps/web/dist ./ COPY ${NGINX_CONF} /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]