CI/CD Pipeline
Overview
Centralize Management System menggunakan Jenkins untuk CI/CD pipeline.
Jenkinsfile
Pipeline Stages
pipeline {
agent {
label 'Server-TSG-VM01'
}
options {
disableConcurrentBuilds()
timeout(time: 15, unit: 'MINUTES')
}
environment {
KUBE_CONFIG = '/opt/clm/k3s/k3s.yaml'
CONFIGS_DIR = '/opt/clm/configs'
ENV_FILE_BE = '/home/jenkins/secret/.env.bjbs-clm-be'
ENV_FILE_FE = '/home/jenkins/secret/.env.bjbs-clm-fe'
FRONTEND_IMAGE = 'clm-frontend:latest'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Sync Configs') {
steps {
sh '''
sudo mkdir -p ${CONFIGS_DIR}
sudo rsync -av --delete configs/ ${CONFIGS_DIR}/
'''
}
}
stage('Build') {
parallel {
stage('Build Backend') {
steps {
sh 'docker compose build backend'
}
}
stage('Build Frontend') {
steps {
sh """
docker build \
--no-cache \
--build-arg VITE_API_BASE_URL=\${VITE_API_BASE_URL:-http://10.8.0.48:8081} \
-f frontend/Dockerfile.prod \
-t ${FRONTEND_IMAGE} \
frontend/
"""
}
}
stage('Build Fluentd') {
steps {
sh 'docker compose build fluentd'
}
}
}
}
stage('Deploy Backend') {
steps {
sh '''
export CONFIGS_DIR=${CONFIGS_DIR}
docker compose \
--env-file ${ENV_FILE_BE} \
up -d --force-recreate backend fluentd \
--build
'''
}
}
stage('Deploy Frontend') {
steps {
sh '''
docker compose \
--env-file ${ENV_FILE_FE} \
up -d --force-recreate frontend
'''
}
}
stage('Health Check') {
options {
timeout(time: 90, unit: 'SECONDS')
}
steps {
sh '''
sleep 30
OK=0; FAIL=0
curl -sf http://localhost:8081/healthz > /dev/null && echo "✅ backend" || { echo "❌ backend"; FAIL=$((FAIL+1)); }
curl -sf http://localhost:8085 > /dev/null && echo "✅ frontend" || { echo "❌ frontend"; FAIL=$((FAIL+1)); }
[ "$FAIL" -gt 0 ] && exit 1 || echo "All services healthy ✅"
'''
}
}
stage('Cleanup') {
steps {
sh 'docker builder prune -f'
}
}
}
post {
success {
echo '✅ Pipeline completed successfully'
}
failure {
echo '❌ Pipeline failed'
}
}
}
Pipeline Flow
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Checkout │────▶│ Sync │────▶│ Build │────▶│ Deploy │
│ │ │ Configs │ │ (Parallel│ │ │
└──────────┘ └──────────┘ └──────────┘ └──────────┘
│
▼
┌──────────┐
│ Health │
│ Check │
└──────────┘
Environment Variables
| Variable | Description | Location |
|---|---|---|
KUBE_CONFIG | K3s kubeconfig | /opt/clm/k3s/k3s.yaml |
CONFIGS_DIR | Configs directory | /opt/clm/configs |
ENV_FILE_BE | Backend env file | /home/jenkins/secret/.env.bjbs-clm-be |
ENV_FILE_FE | Frontend env file | /home/jenkins/secret/.env.bjbs-clm-fe |
Health Checks
| Service | Check | Expected |
|---|---|---|
| Backend | curl http://localhost:8081/healthz | 200 OK |
| Frontend | curl http://localhost:8085 | 200 OK |
| Fluentd | docker exec fluentd cat /fluentd/etc/fluent.conf | Success |
| Camel | curl http://localhost:8181/actuator/health | 200 OK |
| Prometheus | curl http://localhost:9090/-/healthy | 200 OK |
| Grafana | curl http://localhost:3001/api/health | 200 OK |
| RabbitMQ | curl http://localhost:15672/api/overview | 200 OK |
| MinIO | curl http://localhost:9000/minio/health/live | 200 OK |
Manual Deployment
Build & Deploy All
# Build all services
docker compose build
# Deploy all services
docker compose up -d --force-recreate
Deploy Specific Service
# Deploy backend only
docker compose up -d --force-recreate backend
# Deploy frontend only
docker compose up -d --force-recreate frontend
Next Steps
- Kubernetes - K3s deployment
- Troubleshooting - Debugging
- Local Setup - Development setup