fix: 构建前清理本地旧镜像,解决 buildx --load image already exists 错误
CI/CD Pipeline / Unit Tests (push) Failing after 0s
CI/CD Pipeline / Frontend Lint (push) Failing after 0s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 2s
CI/CD Pipeline / Integration Tests (push) Failing after 0s
CI/CD Pipeline / Staging API Integration Tests (push) Failing after 1512h18m33s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Failing after 1512h18m35s
CI/CD Pipeline / Production Browser E2E (push) Failing after 1512h18m36s
CI/CD Pipeline / Build Staging Web Image (push) Failing after 1512h18m36s
CI/CD Pipeline / Build Staging API Image (push) Failing after 1512h18m36s
CI/CD Pipeline / Build Production API Image (push) Failing after 1512h18m38s
CI/CD Pipeline / Deploy Production (push) Failing after 1512h18m37s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 1512h18m38s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 1512h50m15s
CI/CD Pipeline / Build Staging Worker Image (push) Failing after 1512h50m18s
CI/CD Pipeline / Build Production Web Image (push) Failing after 1512h50m20s

This commit is contained in:
XiaoXia Bot
2026-07-15 15:11:31 +08:00
parent 46c7c351af
commit f905c3ef8d
+12
View File
@@ -60,6 +60,9 @@ fi
# 默认只读不写,防止 feature 分支污染主缓存
# 只有 develop/main 分支才写回缓存
BRANCH_NAME="${GITHUB_REF_NAME:-${CI_COMMIT_BRANCH:-unknown}}"
# 清理本地旧镜像
docker rmi -f "$API_IMAGE" "$API_LATEST" 2>/dev/null || true
if [ "$USE_CACHE" -eq 1 ]; then
docker buildx build \
--build-arg APP_VERSION="$VERSION" \
@@ -89,6 +92,9 @@ build_with_cache() {
echo " cache: read-only from ${CACHE_REGISTRY}/${IMG_NAME}-cache:${CACHE_TAG_PRIMARY}"
fi
# 清理本地旧镜像,避免 buildx --load 报 already exists 错误
docker rmi -f "$IMG_NAME:$VERSION" 2>/dev/null || true
if [ "$USE_CACHE" -eq 1 ]; then
if [ -n "$CACHE_TO" ]; then
docker buildx build \
@@ -119,6 +125,9 @@ build_with_cache "api" "infra/docker/api.Dockerfile" \
docker tag "$API_IMAGE" "$API_LATEST"
echo "=== Building Worker image ==="
# 清理本地旧镜像
docker rmi -f "$WORKER_IMAGE" "$WORKER_LATEST" 2>/dev/null || true
if [ "$USE_CACHE" -eq 1 ]; then
docker buildx build \
--build-arg APP_VERSION="$VERSION" \
@@ -148,6 +157,9 @@ docker run --rm \
test -f apps/web/dist/index.html
# 清理本地旧镜像
docker rmi -f "$WEB_IMAGE" 2>/dev/null || true
if [ "$USE_CACHE" -eq 1 ]; then
docker buildx build \
--cache-from "type=registry,ref=${CACHE_REGISTRY}/web-cache:${CACHE_TAG_PRIMARY},ignore-error=true" \