Add complete webhook-based CI/CD with automatic builds and notifications
Some checks failed
Build and Push to Harbor / build-and-push (push) Has been cancelled
Some checks failed
Build and Push to Harbor / build-and-push (push) Has been cancelled
This commit implements a full webhook-triggered CI/CD pipeline: **Flux Components:** - Flux Receiver for Gitea webhooks (generic type, NodePort 30090) - Notification Provider for notify.caffeinetux.com - Alerts for git updates, builds, and deployments **Build Automation:** - Webhook listener deployment that triggers on git push - Automatic Kaniko build jobs with git metadata - Images tagged with both 'latest' and commit SHA - Build notifications sent at start and completion **Workflow:** 1. Push to Gitea → Webhooks trigger Flux receiver & build listener 2. Build listener creates Kaniko job with commit info 3. Kaniko builds and pushes to Harbor (latest + SHA tags) 4. Flux auto-deploys latest image to cluster 5. Notifications sent to notify.caffeinetux.com at each stage **Configuration:** - Token: APMvTuncQJmm6vd - Webhook path: /hook/548969c2b24c717fe9e5af8c78ddfeec40d3024c270c7e85ac8f986259aeec9a - Build trigger: http://<node-ip>:30091/webhook - Comprehensive setup documentation in WEBHOOK_SETUP_GUIDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
223
webhook-build-trigger.yaml
Normal file
223
webhook-build-trigger.yaml
Normal file
@@ -0,0 +1,223 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: webhook-build-script
|
||||
namespace: default
|
||||
data:
|
||||
trigger-build.sh: |
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "===== Git Push Detected - Triggering Build ====="
|
||||
date
|
||||
|
||||
# Clone the repository
|
||||
echo "Cloning repository..."
|
||||
git clone http://192.168.1.49:13001/admin/neon-vortex.git /tmp/repo
|
||||
cd /tmp/repo
|
||||
|
||||
# Get commit info
|
||||
GIT_COMMIT=$(git rev-parse HEAD)
|
||||
GIT_SHORT=$(git rev-parse --short HEAD)
|
||||
GIT_MSG=$(git log -1 --pretty=%B | head -1)
|
||||
GIT_AUTHOR=$(git log -1 --pretty=%an)
|
||||
|
||||
echo "Commit: $GIT_SHORT ($GIT_COMMIT)"
|
||||
echo "Author: $GIT_AUTHOR"
|
||||
echo "Message: $GIT_MSG"
|
||||
|
||||
# Generate unique job name
|
||||
TIMESTAMP=$(date +%s)
|
||||
JOB_NAME="build-${GIT_SHORT}-${TIMESTAMP}"
|
||||
|
||||
echo "Creating build job: $JOB_NAME"
|
||||
|
||||
# Send start notification
|
||||
curl -s -X POST "https://notify.caffeinetux.com?token=APMvTuncQJmm6vd" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"title\": \"🔨 Neon Vortex Build Started\",
|
||||
\"message\": \"Commit: ${GIT_SHORT} by ${GIT_AUTHOR}\\n${GIT_MSG}\",
|
||||
\"priority\": 3,
|
||||
\"tags\": [\"building\"]
|
||||
}" || echo "Notification failed"
|
||||
|
||||
# Create the build job
|
||||
kubectl apply -f - <<EOF
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: $JOB_NAME
|
||||
namespace: default
|
||||
labels:
|
||||
app: neon-vortex
|
||||
build-trigger: webhook
|
||||
git-commit: "$GIT_SHORT"
|
||||
annotations:
|
||||
git-commit-full: "$GIT_COMMIT"
|
||||
git-message: "$GIT_MSG"
|
||||
git-author: "$GIT_AUTHOR"
|
||||
spec:
|
||||
ttlSecondsAfterFinished: 3600
|
||||
backoffLimit: 0
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: neon-vortex
|
||||
build-job: "true"
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
initContainers:
|
||||
- name: git-clone
|
||||
image: alpine/git:latest
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
set -e
|
||||
echo "Cloning and checking out $GIT_COMMIT..."
|
||||
git clone http://192.168.1.49:13001/admin/neon-vortex.git /workspace
|
||||
cd /workspace
|
||||
git checkout $GIT_COMMIT
|
||||
echo "Repository ready for build"
|
||||
env:
|
||||
- name: GIT_COMMIT
|
||||
value: "$GIT_COMMIT"
|
||||
volumeMounts:
|
||||
- name: workspace
|
||||
mountPath: /workspace
|
||||
containers:
|
||||
- name: kaniko
|
||||
image: gcr.io/kaniko-project/executor:latest
|
||||
args:
|
||||
- "--dockerfile=/workspace/htlm/Dockerfile"
|
||||
- "--context=/workspace/htlm"
|
||||
- "--destination=images.caffeinetux.com/apps/neon-vortex:latest"
|
||||
- "--destination=images.caffeinetux.com/apps/neon-vortex:$GIT_SHORT"
|
||||
- "--cache=true"
|
||||
- "--cache-repo=images.caffeinetux.com/apps/neon-vortex/cache"
|
||||
- "--label=git.commit=$GIT_COMMIT"
|
||||
- "--label=git.short=$GIT_SHORT"
|
||||
- "--label=git.message=$GIT_MSG"
|
||||
- "--label=git.author=$GIT_AUTHOR"
|
||||
volumeMounts:
|
||||
- name: workspace
|
||||
mountPath: /workspace
|
||||
- name: docker-config
|
||||
mountPath: /kaniko/.docker
|
||||
- name: notify-completion
|
||||
image: alpine:latest
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
set -e
|
||||
apk add --no-cache curl
|
||||
|
||||
echo "Waiting for Kaniko to complete..."
|
||||
sleep 10
|
||||
|
||||
# Send completion notification
|
||||
curl -s -X POST "https://notify.caffeinetux.com?token=APMvTuncQJmm6vd" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"title\": \"✅ Neon Vortex Build Complete\",
|
||||
\"message\": \"Image built successfully for commit ${GIT_SHORT}\\nDeployment will update automatically\",
|
||||
\"priority\": 3,
|
||||
\"tags\": [\"success\",\"deployed\"]
|
||||
}"
|
||||
|
||||
echo "Completion notification sent"
|
||||
env:
|
||||
- name: GIT_SHORT
|
||||
value: "$GIT_SHORT"
|
||||
volumes:
|
||||
- name: workspace
|
||||
emptyDir: {}
|
||||
- name: docker-config
|
||||
secret:
|
||||
secretName: harbor-registry
|
||||
items:
|
||||
- key: .dockerconfigjson
|
||||
path: config.json
|
||||
EOF
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ Build job $JOB_NAME created successfully"
|
||||
else
|
||||
echo "❌ Failed to create build job"
|
||||
curl -s -X POST "https://notify.caffeinetux.com?token=APMvTuncQJmm6vd" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"title\": \"❌ Neon Vortex Build Failed\",
|
||||
\"message\": \"Failed to create build job for commit ${GIT_SHORT}\",
|
||||
\"priority\": 5,
|
||||
\"tags\": [\"error\"]
|
||||
}"
|
||||
exit 1
|
||||
fi
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: webhook-build-listener
|
||||
namespace: default
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: webhook-build-listener
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: webhook-build-listener
|
||||
spec:
|
||||
serviceAccountName: build-trigger-sa
|
||||
containers:
|
||||
- name: listener
|
||||
image: alpine:latest
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
apk add --no-cache socat bash git curl
|
||||
|
||||
echo "Starting webhook listener on port 8080..."
|
||||
|
||||
while true; do
|
||||
echo "Waiting for webhook trigger..."
|
||||
echo -e "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK" | \
|
||||
socat TCP-LISTEN:8080,reuseaddr,fork STDIO | \
|
||||
while read line; do
|
||||
if echo "$line" | grep -q "POST /webhook"; then
|
||||
echo "Webhook received! Triggering build..."
|
||||
/scripts/trigger-build.sh &
|
||||
break
|
||||
fi
|
||||
done
|
||||
sleep 2
|
||||
done
|
||||
volumeMounts:
|
||||
- name: script
|
||||
mountPath: /scripts
|
||||
volumes:
|
||||
- name: script
|
||||
configMap:
|
||||
name: webhook-build-script
|
||||
defaultMode: 0755
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: webhook-build-listener
|
||||
namespace: default
|
||||
spec:
|
||||
type: NodePort
|
||||
selector:
|
||||
app: webhook-build-listener
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
nodePort: 30091
|
||||
name: webhook
|
||||
Reference in New Issue
Block a user