# Build stage FROM git.xiaoxiajianji.com/xiaoxia/base/node:20 AS builder ARG SOURCE_HASH="" 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 # 安装依赖:node_modules写入镜像layer,走ACR缓存保证完整性 # /root/.npm 保留cache mount加速下载(不影响构建正确性) RUN --mount=type=cache,target=/root/.npm,sharing=locked \ npm ci --registry=https://registry.npmmirror.com # 再拷源码 COPY apps/web/ ./ # 构建:TS增量编译 + Vite构建,tsbuildinfo用cache mount持久化 # node_modules直接使用镜像中已安装的(layer缓存保证完整性) # SOURCE_HASH 变化时强制重新执行(防止 buildkit 幽灵缓存命中) RUN --mount=type=cache,target=/app/apps/web/.tscache,sharing=locked \ mkdir -p .tscache \ && echo "SOURCE_HASH=${SOURCE_HASH}" > .cache_bust \ && ./node_modules/.bin/tsc --incremental --tsBuildInfoFile .tscache/tsconfig.tsbuildinfo \ && ./node_modules/.bin/vite build # Production stage with nginx FROM git.xiaoxiajianji.com/xiaoxia/base/nginx:alpine AS runner WORKDIR /usr/share/nginx/html COPY --from=builder /app/apps/web/dist ./ # 将所有 nginx 配置烤入镜像,entrypoint 按 APP_ENV 选择 COPY infra/docker/nginx.conf /etc/nginx/nginx-production.conf COPY infra/docker/nginx-staging.conf /etc/nginx/nginx-staging.conf COPY infra/docker/nginx-production.conf /etc/nginx/nginx-production.conf COPY infra/docker/nginx-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /docker-entrypoint.sh EXPOSE 80 ENTRYPOINT ["/docker-entrypoint.sh"]