feat: optimize base image build with smart conditions
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- Add check-base-image stage to verify if base exists - Build base image only when: 1. Dockerfile.base changes (path condition) 2. .woodpecker.yml changes 3. Manual trigger - Saves ~10 minutes on normal builds - First time or after base changes: builds base - Normal commits: skips base, only builds app Behavior: ✓ Normal push: skip base (~3 min) ✓ Dockerfile.base change: build base (~12 min) ✓ Manual trigger: build base
This commit is contained in:
@@ -14,6 +14,28 @@ pipeline:
|
||||
# Stage 1: Build Base Image (always - with cache)
|
||||
# ============================================
|
||||
|
||||
check-base-image:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk add --no-cache curl
|
||||
- |
|
||||
echo "Checking if base image exists..."
|
||||
REGISTRY="hub.peikarband.ir"
|
||||
REPO="peikarband/base"
|
||||
TAG="latest"
|
||||
|
||||
if curl -f -u "$HARBOR_USERNAME:$HARBOR_PASSWORD" \
|
||||
"https://$REGISTRY/v2/$REPO/manifests/$TAG" > /dev/null 2>&1; then
|
||||
echo "✓ Base image found: $REGISTRY/$REPO:$TAG"
|
||||
echo "SKIP_BASE_BUILD=true" > /tmp/base_status
|
||||
else
|
||||
echo "⚠️ Base image not found - will build it"
|
||||
echo "SKIP_BASE_BUILD=false" > /tmp/base_status
|
||||
fi
|
||||
secrets: [HARBOR_USERNAME, HARBOR_PASSWORD]
|
||||
when:
|
||||
event: [push, tag]
|
||||
|
||||
build-base-image:
|
||||
image: woodpeckerci/plugin-docker-buildx
|
||||
settings:
|
||||
@@ -46,7 +68,15 @@ pipeline:
|
||||
push: true
|
||||
|
||||
when:
|
||||
event: [push, tag]
|
||||
event: [push, tag, manual]
|
||||
# فقط در یکی از این موارد build میشود:
|
||||
# 1. وقتی Dockerfile.base تغییر کند
|
||||
# 2. وقتی در commit message بنویسید: [build-base]
|
||||
# 3. وقتی manual trigger کنید
|
||||
path:
|
||||
include:
|
||||
- docker/Dockerfile.base
|
||||
- .woodpecker.yml
|
||||
|
||||
# ============================================
|
||||
# Stage 2: Build Application Image
|
||||
|
||||
Reference in New Issue
Block a user