perf(ci): 恢复registry cache-to写入,ACR已改为tag可变
AI Code Review / AI Code Review (pull_request) Successful in 2m51s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 2m46s
PR Automation / Auto Approve on CI Green (pull_request) Failing after 2m51s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 2m28s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 21s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1365h41m50s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 1365h41m53s
CI/CD Pipeline / Check if frontend-only change (pull_request) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (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 / Build Staging API Image (pull_request) Failing after 1366h14m4s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1366h14m1s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 1366h14m3s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 1366h13m59s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1366h14m1s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 1366h14m2s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 1366h14m3s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1366h14m0s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1366h14m1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 1366h13m53s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 1366h14m3s

- 恢复2处--cache-to type=registry写入
- 保留ignore-error=true作为兜底(防止ACR配置回退导致构建失败)
- cache-from的ignore-error也去掉了(tag可变后正常写入不会报错)

前提:阿里云ACR缓存仓库(api-cache/worker-cache/web-cache)已从不可变改为可变tag
This commit is contained in:
2026-07-21 13:54:09 +08:00
parent cffe84c764
commit 933973311f
+8 -6
View File
@@ -1,6 +1,5 @@
#!/bin/bash
# 通用Docker镜像构建+推送脚本(local cache为主 + registry cache兜底)
# M-2优化:解决registry缓存导入慢(247s)和推送不稳定问题
# 通用Docker镜像构建+推送脚本(local cache为主 + registry cache共享)
# 用法: docker_build_push.sh [--no-cache] <Dockerfile> <image_tag> <cache_ref> [build_arg...]
set -eu
@@ -35,7 +34,7 @@ LOCAL_CACHE_DIR="/tmp/buildx-cache/${CACHE_NAME}"
mkdir -p "$LOCAL_CACHE_DIR"
# 缓存源:local优先(带自动修复),registry兜底
# 缓存源:local优先(带自动修复),registry兜底读写
# 本地缓存损坏时自动清理后重试,避免snapshot not found导致构建全挂
build_with_cache_retry() {
local attempt=1
@@ -48,8 +47,9 @@ build_with_cache_retry() {
$NO_CACHE_FLAG \
$BUILD_ARGS \
--cache-from "type=local,src=${LOCAL_CACHE_DIR}" \
--cache-from "type=registry,ref=${CACHE_REF},ignore-error=true" \
--cache-from "type=registry,ref=${CACHE_REF}" \
--cache-to "type=local,dest=${LOCAL_CACHE_DIR},mode=max" \
--cache-to "type=registry,ref=${CACHE_REF},mode=max,ignore-error=true" \
-f "${DOCKERFILE}" \
-t "${IMAGE_TAG}" \
--push \
@@ -81,15 +81,16 @@ build_with_cache_retry() {
docker buildx build \
$NO_CACHE_FLAG \
$BUILD_ARGS \
--cache-from "type=registry,ref=${CACHE_REF},ignore-error=true" \
--cache-from "type=registry,ref=${CACHE_REF}" \
--cache-to "type=local,dest=${LOCAL_CACHE_DIR},mode=max" \
--cache-to "type=registry,ref=${CACHE_REF},mode=max,ignore-error=true" \
-f "${DOCKERFILE}" \
-t "${IMAGE_TAG}" \
--push \
.
}
echo "=== Step 1: Build & push image (local cache + registry read, with auto-repair) ==="
echo "=== Step 1: Build & push image (local cache + registry cache, with auto-repair) ==="
echo "Local cache: ${LOCAL_CACHE_DIR}"
echo "Registry cache: ${CACHE_REF}"
echo ""
@@ -99,6 +100,7 @@ build_with_cache_retry
echo ""
echo "Image pushed: ${IMAGE_TAG}"
echo "Local cache updated"
echo "Registry cache updated (if supported)"
echo ""
echo "Build completed: ${IMAGE_TAG}"