feat: add smart base image management to pipeline
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

Pipeline now handles base image automatically:

 ensure-base-image:
   • Checks if Dockerfile.base changed
   • Only rebuilds if needed
   • Saves ~10 minutes when unchanged

 build-and-push-app:
   • Uses base image
   • Fast build (~3 minutes)

 verify-images:
   • Confirms both images exist
   • Shows available tags

Behavior:
─────────
1️⃣  Dockerfile.base changed:
    → Build base (~10 min)
    → Build app (~3 min)
    → Total: ~13 min

2️⃣  Only code changed:
    → Skip base (path filter)
    → Build app (~3 min)
    → Total: ~3 min 

This is the smart solution we wanted!
This commit is contained in:
Ehsan.Asadi
2025-12-30 22:21:17 +03:30
parent 826447e9a2
commit 6fe58c3815

View File

@@ -1,22 +1,68 @@
# Woodpecker CI/CD Pipeline - Peikarband Landing
# Simple and efficient pipeline
# Smart pipeline with base image management
variables:
- &helm_image 'alpine/helm:latest'
- &base_image 'hub.peikarband.ir/peikarband/base:latest'
- &app_image 'hub.peikarband.ir/peikarband/landing'
when:
- event: [push, pull_request, tag, manual]
pipeline:
# ============================================
# Build Application Image (with fallback to python base)
# Ensure Base Image Exists
# ============================================
ensure-base-image:
image: woodpeckerci/plugin-docker-buildx
settings:
registry: hub.peikarband.ir
repo: hub.peikarband.ir/peikarband/base
username:
from_secret: HARBOR_USERNAME
password:
from_secret: HARBOR_PASSWORD
dockerfile: docker/Dockerfile.base
context: .
platforms: linux/amd64
tags:
- latest
- python3.11-node20
build_args:
- PYTHON_VERSION=3.11
- NODE_VERSION=20
labels:
- org.opencontainers.image.created=${CI_PIPELINE_CREATED}
- org.opencontainers.image.source=${CI_REPO_LINK}
- org.opencontainers.image.title=Peikarband Base
- org.opencontainers.image.description=Base image with Python, Node.js, bun, and build tools
pull: true
provenance: false
push: true
when:
event: [push, tag, manual]
branch: [main, develop, feature/restructure-project]
# Only rebuild base if its definition changed
path:
include:
- docker/Dockerfile.base
- .woodpecker.yml
# ============================================
# Build Application Image
# ============================================
build-and-push-app:
image: woodpeckerci/plugin-docker-buildx
settings:
registry: hub.peikarband.ir
repo: hub.peikarband.ir/peikarband/landing
repo: *app_image
username:
from_secret: HARBOR_USERNAME
password:
@@ -27,7 +73,7 @@ pipeline:
platforms: linux/amd64
build_args:
- BASE_IMAGE=hub.peikarband.ir/peikarband/base:latest
- BASE_IMAGE=*base_image
- VERSION=${CI_COMMIT_SHA:0:8}
- BUILD_DATE=${CI_PIPELINE_CREATED}
@@ -54,33 +100,48 @@ pipeline:
branch: [main, develop, feature/restructure-project]
# ============================================
# Verify Push
# Verify Images
# ============================================
verify-push:
verify-images:
image: alpine:latest
commands:
- apk add --no-cache curl
- |
echo "Verifying image was pushed successfully..."
sleep 3
REGISTRY="hub.peikarband.ir"
REPO="peikarband/landing"
TAG="${CI_COMMIT_SHA:0:8}"
echo "════════════════════════════════════════"
echo " 🔍 Verifying Images in Registry"
echo "════════════════════════════════════════"
echo ""
# Check base image
echo "Checking base image..."
if curl -f -u "$HARBOR_USERNAME:$HARBOR_PASSWORD" \
"https://$REGISTRY/v2/$REPO/manifests/$TAG" > /dev/null 2>&1; then
echo "✅ Image verified: $REGISTRY/$REPO:$TAG"
"https://hub.peikarband.ir/v2/peikarband/base/manifests/latest" > /dev/null 2>&1; then
echo "✅ Base image: hub.peikarband.ir/peikarband/base:latest"
else
echo "⚠️ Base image not found (this is OK if first build)"
fi
echo ""
# Check app image
echo "Checking app image..."
TAG="${CI_COMMIT_SHA:0:8}"
if curl -f -u "$HARBOR_USERNAME:$HARBOR_PASSWORD" \
"https://hub.peikarband.ir/v2/peikarband/landing/manifests/$TAG" > /dev/null 2>&1; then
echo "✅ App image: hub.peikarband.ir/peikarband/landing:$TAG"
echo ""
echo "Available tags:"
echo " - latest"
echo " - ${CI_COMMIT_SHA:0:8}"
echo " - ${CI_COMMIT_BRANCH}"
echo " latest"
echo " ${CI_COMMIT_SHA:0:8}"
echo " ${CI_COMMIT_BRANCH}"
echo ""
echo "════════════════════════════════════════"
else
echo "❌ Failed to verify image push"
echo "❌ Failed to verify app image"
exit 1
fi
secrets: [HARBOR_USERNAME, HARBOR_PASSWORD]
when:
event: [push, tag]
@@ -99,7 +160,14 @@ pipeline:
- echo ""
- echo "Branch:" "${CI_COMMIT_BRANCH}"
- echo "Commit:" "${CI_COMMIT_SHA:0:8}"
- echo "Image:" "hub.peikarband.ir/peikarband/landing:${CI_COMMIT_SHA:0:8}"
- echo ""
- echo "Images:"
- echo " • Base:" "hub.peikarband.ir/peikarband/base:latest"
- echo " • App:" "hub.peikarband.ir/peikarband/landing:${CI_COMMIT_SHA:0:8}"
- echo ""
- echo "Deploy with:"
- echo " kubectl set image deployment/peikarband-landing \\"
- echo " peikarband-landing=hub.peikarband.ir/peikarband/landing:${CI_COMMIT_SHA:0:8}"
- echo ""
- echo "════════════════════════════════════════"
when: