99fa146a5c
CI/CD Pipeline / Frontend Lint (push) Successful in 1m32s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m31s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 2m44s
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 Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m49s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 2m52s
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 / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (push) Successful in 2m54s
CI/CD Pipeline / Build Staging API Image (push) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Has been skipped
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (push) Has been skipped
CI/CD Pipeline / Staging E2E Tests (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m29s
CI/CD Pipeline / Integration Tests (push) Successful in 1m25s
- 新增docker_build_push.sh通用脚本 - 构建镜像(只读缓存)与推送缓存分离 - 缓存推送失败重试3次,不影响主构建结果 - 使用zstd压缩缓存层
72 lines
1.7 KiB
Bash
Executable File
72 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# 通用Docker镜像构建+推送脚本(构建与缓存解耦)
|
|
# 用法: docker_build_push.sh <Dockerfile> <image_tag> <cache_ref> [build_arg...]
|
|
set -eu
|
|
|
|
DOCKERFILE="$1"
|
|
IMAGE_TAG="$2"
|
|
CACHE_REF="$3"
|
|
shift 3
|
|
BUILD_ARGS=""
|
|
for arg in "$@"; do
|
|
BUILD_ARGS="$BUILD_ARGS --build-arg $arg"
|
|
done
|
|
|
|
if ! docker buildx inspect ci-builder > /dev/null 2>&1; then
|
|
docker buildx create --use --name ci-builder --driver docker-container
|
|
echo "Created ci-builder"
|
|
else
|
|
docker buildx use ci-builder
|
|
echo "Using existing ci-builder"
|
|
fi
|
|
docker buildx inspect --bootstrap
|
|
|
|
CACHE_FROM="type=registry,ref=${CACHE_REF},ignore-error=true"
|
|
|
|
echo "=== Step 1: Build & push image (read-only cache) ==="
|
|
docker buildx build \
|
|
$BUILD_ARGS \
|
|
--cache-from "${CACHE_FROM}" \
|
|
-f "${DOCKERFILE}" \
|
|
-t "${IMAGE_TAG}" \
|
|
--push \
|
|
.
|
|
|
|
echo "Image pushed: ${IMAGE_TAG}"
|
|
|
|
echo ""
|
|
echo "=== Step 2: Push cache (best effort, retries 3x) ==="
|
|
CACHE_TO="type=registry,ref=${CACHE_REF},mode=max,compression=zstd"
|
|
|
|
MAX_RETRIES=3
|
|
SUCCESS=0
|
|
for attempt in $(seq 1 $MAX_RETRIES); do
|
|
echo "Cache push attempt $attempt/$MAX_RETRIES"
|
|
if docker buildx build \
|
|
$BUILD_ARGS \
|
|
--cache-from "${CACHE_FROM}" \
|
|
--cache-to "${CACHE_TO}" \
|
|
-f "${DOCKERFILE}" \
|
|
-t "${IMAGE_TAG}" \
|
|
--push \
|
|
.; then
|
|
echo "Cache pushed (attempt $attempt)"
|
|
SUCCESS=1
|
|
break
|
|
else
|
|
echo "Cache push failed (attempt $attempt)"
|
|
if [ $attempt -lt $MAX_RETRIES ]; then
|
|
WAIT=$((attempt * 5))
|
|
echo "Retrying in ${WAIT}s..."
|
|
sleep $WAIT
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [ $SUCCESS -eq 0 ]; then
|
|
echo "WARNING: Cache push failed after $MAX_RETRIES attempts (non-fatal)"
|
|
fi
|
|
|
|
echo ""
|
|
echo "Build completed: ${IMAGE_TAG}"
|