feat: add smart base image management to pipeline
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
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:
108
.woodpecker.yml
108
.woodpecker.yml
@@ -1,22 +1,68 @@
|
|||||||
# Woodpecker CI/CD Pipeline - Peikarband Landing
|
# Woodpecker CI/CD Pipeline - Peikarband Landing
|
||||||
# Simple and efficient pipeline
|
# Smart pipeline with base image management
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
- &helm_image 'alpine/helm:latest'
|
- &base_image 'hub.peikarband.ir/peikarband/base:latest'
|
||||||
|
- &app_image 'hub.peikarband.ir/peikarband/landing'
|
||||||
|
|
||||||
when:
|
when:
|
||||||
- event: [push, pull_request, tag, manual]
|
- event: [push, pull_request, tag, manual]
|
||||||
|
|
||||||
pipeline:
|
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:
|
build-and-push-app:
|
||||||
image: woodpeckerci/plugin-docker-buildx
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
settings:
|
settings:
|
||||||
registry: hub.peikarband.ir
|
registry: hub.peikarband.ir
|
||||||
repo: hub.peikarband.ir/peikarband/landing
|
repo: *app_image
|
||||||
username:
|
username:
|
||||||
from_secret: HARBOR_USERNAME
|
from_secret: HARBOR_USERNAME
|
||||||
password:
|
password:
|
||||||
@@ -27,7 +73,7 @@ pipeline:
|
|||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
|
|
||||||
build_args:
|
build_args:
|
||||||
- BASE_IMAGE=hub.peikarband.ir/peikarband/base:latest
|
- BASE_IMAGE=*base_image
|
||||||
- VERSION=${CI_COMMIT_SHA:0:8}
|
- VERSION=${CI_COMMIT_SHA:0:8}
|
||||||
- BUILD_DATE=${CI_PIPELINE_CREATED}
|
- BUILD_DATE=${CI_PIPELINE_CREATED}
|
||||||
|
|
||||||
@@ -54,33 +100,48 @@ pipeline:
|
|||||||
branch: [main, develop, feature/restructure-project]
|
branch: [main, develop, feature/restructure-project]
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# Verify Push
|
# Verify Images
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
||||||
verify-push:
|
verify-images:
|
||||||
image: alpine:latest
|
image: alpine:latest
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache curl
|
- apk add --no-cache curl
|
||||||
- |
|
- |
|
||||||
echo "Verifying image was pushed successfully..."
|
echo "════════════════════════════════════════"
|
||||||
sleep 3
|
echo " 🔍 Verifying Images in Registry"
|
||||||
|
echo "════════════════════════════════════════"
|
||||||
REGISTRY="hub.peikarband.ir"
|
echo ""
|
||||||
REPO="peikarband/landing"
|
|
||||||
TAG="${CI_COMMIT_SHA:0:8}"
|
|
||||||
|
|
||||||
|
# Check base image
|
||||||
|
echo "Checking base image..."
|
||||||
if curl -f -u "$HARBOR_USERNAME:$HARBOR_PASSWORD" \
|
if curl -f -u "$HARBOR_USERNAME:$HARBOR_PASSWORD" \
|
||||||
"https://$REGISTRY/v2/$REPO/manifests/$TAG" > /dev/null 2>&1; then
|
"https://hub.peikarband.ir/v2/peikarband/base/manifests/latest" > /dev/null 2>&1; then
|
||||||
echo "✅ Image verified: $REGISTRY/$REPO:$TAG"
|
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 ""
|
||||||
echo "Available tags:"
|
echo "Available tags:"
|
||||||
echo " - latest"
|
echo " • latest"
|
||||||
echo " - ${CI_COMMIT_SHA:0:8}"
|
echo " • ${CI_COMMIT_SHA:0:8}"
|
||||||
echo " - ${CI_COMMIT_BRANCH}"
|
echo " • ${CI_COMMIT_BRANCH}"
|
||||||
|
echo ""
|
||||||
|
echo "════════════════════════════════════════"
|
||||||
else
|
else
|
||||||
echo "❌ Failed to verify image push"
|
echo "❌ Failed to verify app image"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
secrets: [HARBOR_USERNAME, HARBOR_PASSWORD]
|
secrets: [HARBOR_USERNAME, HARBOR_PASSWORD]
|
||||||
when:
|
when:
|
||||||
event: [push, tag]
|
event: [push, tag]
|
||||||
@@ -99,7 +160,14 @@ pipeline:
|
|||||||
- echo ""
|
- echo ""
|
||||||
- echo "Branch:" "${CI_COMMIT_BRANCH}"
|
- echo "Branch:" "${CI_COMMIT_BRANCH}"
|
||||||
- echo "Commit:" "${CI_COMMIT_SHA:0:8}"
|
- 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 ""
|
||||||
- echo "════════════════════════════════════════"
|
- echo "════════════════════════════════════════"
|
||||||
when:
|
when:
|
||||||
|
|||||||
Reference in New Issue
Block a user