bc9df316dc
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 1s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Check push changed paths (push) Successful in 16s
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 3m16s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Failing after 6m4s
CI/CD Pipeline / Validate - Style (pull_request) Has been skipped
CI/CD Pipeline / Validate - Security (pull_request) Has been skipped
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 39s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Style (push) Has been cancelled
CI/CD Pipeline / Validate - Security (push) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Retag skipped Staging API Image (push) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
CI/CD Pipeline / CI Gate (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
问题:ci-builder-persist 持久化 builder 的 buildkit 层缓存偶尔出现'幽灵命中': COPY apps/web/ ./ 步骤认为自己没变(实际文件已改),导致 vite build 不执行, 打出来的 Web 镜像前端文件是旧的。 修复原理: 把 apps/web/ 目录的 git tree hash 作为 build arg 传入 Dockerfile。 buildx 把 build arg 值作为缓存键的一部分,hash 变了 → RUN 步骤缓存失效 → vite build 必须重新执行。依赖层(npm ci)不受影响,仍然正常缓存。 改动: 1. web.Dockerfile:新增 ARG SOURCE_HASH,在构建步骤写入 .cache_bust 文件 2. docker_build_push.sh:Web 镜像构建时计算 git tree hash 并传入 3. docker_build_only.sh:同上 验证: - 合并后触发 push 到 develop - 查看 Build Staging Web Image 日志,确认输出 Web cache bust: SOURCE_HASH=xxxxx - 修改 apps/web/ 下文件再次 push,确认 SOURCE_HASH 值变化且 vite build 执行
37 lines
1.4 KiB
Docker
Executable File
37 lines
1.4 KiB
Docker
Executable File
# 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
|
|
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;"]
|