Files
CloudOps/platform/Jenkinsfile
root 4dd4b8ef9b Checkout: hostPath-mount the VPS's own CloudOps checkout instead of cloning
18 straight clone failures today (early EOF / invalid index-pack) even with
http.postBuffer/http.version tuning applied — Gitea's HTTP endpoint itself is
degraded right now, not something fixable client-side. Sidesteps it entirely:
the docker-agent pod template now hostPath-mounts /root/CloudOps (read-only,
see k3s-cloud-init.groovy) and Checkout just `cp -r`s from it, no network
fetch at all. Build/SonarQube paths revert to ./platform/ (no more repo/
subdirectory, since we're not cloning into one).

Real tradeoff, accepted deliberately: builds now reflect whatever's on the
VPS's disk at build time, not necessarily what's pushed to Gitea. Depends on
/root/CloudOps being kept current via the normal git pull workflow.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-20 11:55:41 +02:00

89 lines
3.1 KiB
Groovy

pipeline {
agent {
kubernetes {
cloud 'k3s-jenkins-agents'
label 'docker-agent'
defaultContainer 'docker-cli'
}
}
options {
skipDefaultCheckout()
}
stages {
stage('Checkout') {
steps {
sh '''
echo "Copying CloudOps from the VPS's own checkout (hostPath-mounted, no Gitea fetch)..."
cp -r /root/CloudOps/. .
test -f platform/app.py
'''
}
}
stage('Build Docker Image') {
steps {
sh '''
docker build -t management-platform:${BUILD_NUMBER} -t management-platform:latest ./platform/
echo "✅ Docker image built"
docker images management-platform:${BUILD_NUMBER} --format "Size: {{.Size}}"
'''
}
}
stage('SonarQube Analysis') {
steps {
container('sonar-scanner') {
withSonarQubeEnv('sonarqube') {
script {
def scannerHome = tool 'sonar-scanner'
sh """
${scannerHome}/bin/sonar-scanner \
-Dsonar.projectKey=management-platform \
-Dsonar.sources=platform \
-Dsonar.python.version=3
"""
}
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
container('docker-cli') {
sh '''
docker save management-platform:${BUILD_NUMBER} | \
/usr/local/bin/k3s ctr -a /run/k3s/containerd/containerd.sock -n k8s.io images import -
set +x
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
/usr/local/bin/k3s kubectl --server=https://kubernetes.default.svc \
--token="$TOKEN" --certificate-authority="$CACERT" \
set image deployment/management-platform \
management-platform=management-platform:${BUILD_NUMBER} \
-n management-platform
/usr/local/bin/k3s kubectl --server=https://kubernetes.default.svc \
--token="$TOKEN" --certificate-authority="$CACERT" \
rollout status deployment/management-platform -n management-platform --timeout=90s
echo "✅ Deployed management-platform:${BUILD_NUMBER} to Kubernetes"
'''
}
}
}
}
post {
success {
echo '✅ Pipeline succeeded — build + Sonar passed, deployed to k8s'
}
failure {
echo '❌ Pipeline failed — check logs'
}
}
}