diff --git a/.woodpecker.yml b/.woodpecker.yml index 68d065a..b7d8996 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -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: