38c9c545cf
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 18s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 40s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m16s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m32s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 3m8s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m11s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 3m7s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m14s
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Successful in 5m21s
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 5m29s
- 新增build-pr job:PR阶段只构建不推送,验证Dockerfile/构建脚本 - auto-approve/auto-merge的CONTEXTS加入3个PR Build检查 - build-staging构建后自动清理buildx builder,防磁盘泄漏 - 新增scripts/ci/docker_build_only.sh:PR构建专用(只读缓存不写) - 新增scripts/agent-commit.sh:Agent提交前自动black+isort+ruff检查
85 lines
2.2 KiB
Bash
Executable File
85 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# PR构建专用:只构建不推送,只读缓存不写,用于PR阶段验证Dockerfile
|
|
set -eu
|
|
|
|
NO_CACHE_FLAG=""
|
|
if [ "$1" = "--no-cache" ]; then
|
|
NO_CACHE_FLAG="--no-cache"
|
|
shift
|
|
fi
|
|
|
|
DOCKERFILE="$1"
|
|
IMAGE_TAG="$2"
|
|
CACHE_REF="$3"
|
|
shift 3
|
|
BUILD_ARGS=""
|
|
for arg in "$@"; do
|
|
BUILD_ARGS="$BUILD_ARGS --build-arg $arg"
|
|
done
|
|
|
|
BUILDER_NAME="ci-pr-builder-${GITHUB_RUN_ID:-local}"
|
|
if ! docker buildx inspect "$BUILDER_NAME" > /dev/null 2>&1; then
|
|
docker buildx create --use --name "$BUILDER_NAME" --driver docker-container
|
|
else
|
|
docker buildx use "$BUILDER_NAME"
|
|
fi
|
|
docker buildx inspect --bootstrap
|
|
|
|
CACHE_NAME=$(echo "$CACHE_REF" | tr "/" "_" | tr ":" "-")
|
|
LOCAL_CACHE_DIR="/tmp/buildx-cache/${CACHE_NAME}"
|
|
mkdir -p "$LOCAL_CACHE_DIR"
|
|
|
|
echo "=== PR Build: build only, no push, read-only cache ==="
|
|
echo "Dockerfile: ${DOCKERFILE}"
|
|
echo "Image tag: ${IMAGE_TAG}"
|
|
echo ""
|
|
|
|
build_with_retry() {
|
|
local attempt=1
|
|
local max_attempts=2
|
|
while [ $attempt -le $max_attempts ]; do
|
|
local build_output
|
|
local exit_code
|
|
set +e
|
|
build_output=$(docker buildx build \
|
|
$NO_CACHE_FLAG \
|
|
$BUILD_ARGS \
|
|
--cache-from "type=local,src=${LOCAL_CACHE_DIR}" \
|
|
--cache-from "type=registry,ref=${CACHE_REF}" \
|
|
-f "${DOCKERFILE}" \
|
|
-t "${IMAGE_TAG}" \
|
|
--load \
|
|
. 2>&1)
|
|
exit_code=$?
|
|
set -e
|
|
if [ $exit_code -eq 0 ]; then
|
|
echo "$build_output"
|
|
return 0
|
|
fi
|
|
if echo "$build_output" | grep -qE "parent snapshot.*not found|snapshot.*does not exist|cache.*corrupt|failed to compute cache key"; then
|
|
echo "$build_output"
|
|
echo "Local cache corrupted, cleaning and retrying ($attempt/$max_attempts)..."
|
|
rm -rf "${LOCAL_CACHE_DIR}"
|
|
mkdir -p "${LOCAL_CACHE_DIR}"
|
|
docker buildx prune -f -a >/dev/null 2>&1 || true
|
|
attempt=$((attempt + 1))
|
|
else
|
|
echo "$build_output"
|
|
return $exit_code
|
|
fi
|
|
done
|
|
echo "Local cache failed, building with registry cache only..."
|
|
docker buildx build \
|
|
$NO_CACHE_FLAG \
|
|
$BUILD_ARGS \
|
|
--cache-from "type=registry,ref=${CACHE_REF}" \
|
|
-f "${DOCKERFILE}" \
|
|
-t "${IMAGE_TAG}" \
|
|
--load \
|
|
.
|
|
}
|
|
|
|
build_with_retry
|
|
echo ""
|
|
echo "PR build OK (not pushed): ${IMAGE_TAG}"
|