From 0694d10b7a8db4f733fff1a44b70032b2a9420cc Mon Sep 17 00:00:00 2001 From: "Ehsan.Asadi" Date: Tue, 30 Dec 2025 22:06:31 +0330 Subject: [PATCH] feat: optimize base image build with smart conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .woodpecker.yml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 2cebf52..65dbb81 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -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