feat(woodpecker): add change detection and selective builds
- Add detect-changes step to check for code changes - Add multiple tags (commit SHA, latest, branch-latest) - Add Kubernetes deployment step - Skip build/deploy if no relevant file changes - Consistent with backend CI pipeline
This commit is contained in:
parent
10b6c48f1b
commit
365ffd3b62
1 changed files with 92 additions and 4 deletions
|
|
@ -1,8 +1,40 @@
|
||||||
when:
|
when:
|
||||||
branch: high-performance
|
branch: [main, high-performance]
|
||||||
event: push
|
event: push
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
# Step 1: Detect if changes exist
|
||||||
|
- name: detect-changes
|
||||||
|
image: alpine/git
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache bash
|
||||||
|
- |
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Get changed files from last commit
|
||||||
|
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD || echo "")
|
||||||
|
|
||||||
|
# Check if relevant files changed (src, package.json, Dockerfile, etc.)
|
||||||
|
RELEVANT_CHANGED=false
|
||||||
|
if echo "$CHANGED_FILES" | grep -qE "^(src/|package\.json|package-lock\.json|Dockerfile|vite\.config|tsconfig|public/)"; then
|
||||||
|
RELEVANT_CHANGED=true
|
||||||
|
echo "✅ Admin panel code changed - will build"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create marker file
|
||||||
|
if [ "$RELEVANT_CHANGED" = "true" ]; then
|
||||||
|
echo "SHOULD_BUILD=true" > .build-marker
|
||||||
|
echo "🚀 Will build admin panel"
|
||||||
|
else
|
||||||
|
echo "SHOULD_BUILD=false" > .build-marker
|
||||||
|
echo "⏭️ Skipping admin panel - no relevant changes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Export for other steps
|
||||||
|
cat .build-marker >> ${CI_ENV}
|
||||||
|
|
||||||
|
# Step 2: Build and push Docker image (only if changed)
|
||||||
- name: build-and-push
|
- name: build-and-push
|
||||||
image: woodpeckerci/plugin-docker-buildx:5.0.0
|
image: woodpeckerci/plugin-docker-buildx:5.0.0
|
||||||
settings:
|
settings:
|
||||||
|
|
@ -10,14 +42,70 @@ steps:
|
||||||
repo: ghcr.io/traceworks2023/nxtgauge-admin-solid
|
repo: ghcr.io/traceworks2023/nxtgauge-admin-solid
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
tags:
|
tags:
|
||||||
|
- ${CI_COMMIT_SHA}
|
||||||
|
- latest
|
||||||
- high-performance-latest
|
- high-performance-latest
|
||||||
username:
|
username:
|
||||||
from_secret: GHCR_USERNAME
|
from_secret: GHCR_USERNAME
|
||||||
password:
|
password:
|
||||||
from_secret: GHCR_TOKEN
|
from_secret: GHCR_TOKEN
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
|
when:
|
||||||
|
- evaluate: 'env.SHOULD_BUILD == "true"'
|
||||||
|
|
||||||
|
# Step 3: Deploy to Kubernetes (only if changed)
|
||||||
|
- name: deploy
|
||||||
|
image: bitnami/kubectl:latest
|
||||||
|
secrets: [kube_config]
|
||||||
|
commands:
|
||||||
|
- |
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check if we should deploy
|
||||||
|
if [ "${SHOULD_BUILD}" != "true" ]; then
|
||||||
|
echo "⏭️ Skipping deployment - no changes"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Setup kubeconfig
|
||||||
|
mkdir -p ~/.kube
|
||||||
|
echo "$KUBE_CONFIG" | base64 -d > ~/.kube/config
|
||||||
|
chmod 600 ~/.kube/config
|
||||||
|
|
||||||
|
NAMESPACE="nxtgauge"
|
||||||
|
DEPLOYMENT_NAME="nxtgauge-admin-solid"
|
||||||
|
|
||||||
|
echo "🚀 Deploying admin panel..."
|
||||||
|
|
||||||
|
# Trigger rolling restart to pick up new image
|
||||||
|
kubectl rollout restart deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE}
|
||||||
|
|
||||||
|
# Wait for rollout to complete
|
||||||
|
echo "⏳ Waiting for rollout to complete..."
|
||||||
|
kubectl rollout status deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE} --timeout=300s
|
||||||
|
|
||||||
|
echo "✅ Admin panel deployed successfully!"
|
||||||
|
|
||||||
|
# Show deployment status
|
||||||
|
kubectl get deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE}
|
||||||
|
when:
|
||||||
|
- evaluate: 'env.SHOULD_BUILD == "true"'
|
||||||
|
- branch: [main, high-performance]
|
||||||
|
|
||||||
|
# Step 4: Notify status
|
||||||
|
- name: notify
|
||||||
|
image: alpine:latest
|
||||||
|
commands:
|
||||||
|
- |
|
||||||
|
if [ "${SHOULD_BUILD}" = "true" ]; then
|
||||||
|
if [ "${CI_PIPELINE_STATUS}" = "success" ]; then
|
||||||
|
echo "✅ Admin panel pipeline completed successfully"
|
||||||
|
else
|
||||||
|
echo "❌ Admin panel pipeline failed"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "⏭️ Admin panel was skipped (no changes)"
|
||||||
|
fi
|
||||||
|
when:
|
||||||
|
- status: [success, failure]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue