Jenkins CI/CD 파이프라인 업데이트

- Jenkinsfile 개선: SonarQube 분석, Quality Gate 추가
- 환경별 설정 파일 업데이트 (dev/staging/prod)
- Kustomize base 및 overlay 파일 정리
- prod 환경 overlay 파일 추가
- 배포 스크립트 및 검증 스크립트 업데이트
- 파이프라인 가이드 문서 업데이트

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ondal
2025-12-01 12:57:35 +09:00
parent b467b84426
commit 0f054109bb
48 changed files with 372 additions and 387 deletions
+60 -8
View File
@@ -59,6 +59,7 @@ podTemplate(
],
volumes: [
emptyDirVolume(mountPath: '/home/gradle/.gradle', memory: false),
emptyDirVolume(mountPath: '/root/.azure', memory: false),
emptyDirVolume(mountPath: '/run/podman', memory: false)
]
) {
@@ -78,6 +79,7 @@ podTemplate(
stage("Setup Kubernetes") {
container('kubectl') {
sh """
kubectl config use-context ${props.context}
kubectl create namespace ${props.namespace} --dry-run=client -o yaml | kubectl apply -f -
"""
}
@@ -92,25 +94,73 @@ podTemplate(
}
}
stage('SonarQube Analysis & Quality Gate') {
if (skipSonarQube) {
echo "⏭️ Skipping SonarQube Analysis (SKIP_SONARQUBE=${params.SKIP_SONARQUBE})"
} else {
container('gradle') {
// 각 서비스별로 개별적으로 SonarQube 분석 및 Quality Gate 확인
services.each { service ->
withSonarQubeEnv('SonarQube') {
echo "🔍 Starting SonarQube analysis for ${service}..."
// 서비스별 테스트 및 SonarQube 분석
sh """
./gradlew :${service}:test :${service}:jacocoTestReport :${service}:sonar \
-Dsonar.projectKey=phonebill-${service}-${environment} \
-Dsonar.projectName=phonebill-${service}-${environment} \
-Dsonar.java.binaries=build/classes/java/main \
-Dsonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml \
-Dsonar.exclusions=**/config/**,**/entity/**,**/dto/**,**/*Application.class,**/exception/**
"""
echo "✅ SonarQube analysis completed for ${service}"
}
// 각 서비스별 Quality Gate 확인
timeout(time: 5, unit: 'MINUTES') {
echo "⏳ Waiting for Quality Gate result for ${service}..."
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "❌ Quality Gate failed for ${service}: ${qg.status}"
} else {
echo "✅ Quality Gate passed for ${service}"
}
}
}
echo "🎉 All services passed SonarQube Quality Gates!"
}
}
}
stage('Build & Push Images') {
timeout(time: 30, unit: 'MINUTES') {
container('podman') {
withCredentials([
usernamePassword(
credentialsId: 'imagereg-credentials',
usernameVariable: 'IMG_USERNAME',
passwordVariable: 'IMG_PASSWORD'
),
usernamePassword(
credentialsId: 'dockerhub-credentials',
usernameVariable: 'DOCKERHUB_USERNAME',
passwordVariable: 'DOCKERHUB_PASSWORD'
)
]) {
// Docker Hub 로그인 (rate limit 해결)
sh "podman login docker.io --username \$DOCKERHUB_USERNAME --password \$DOCKERHUB_PASSWORD"
// Image Registry 로그인
sh "podman login docker.io --username \$IMG_USERNAME --password \$IMG_PASSWORD"
services.each { service ->
sh """
podman build \\
--build-arg BUILD_LIB_DIR="${service}/build/libs" \\
--build-arg ARTIFACTORY_FILE="${service}.jar" \\
-f deployment/container/Dockerfile-backend \\
podman build \
--build-arg BUILD_LIB_DIR="${service}/build/libs" \
--build-arg ARTIFACTORY_FILE="${service}.jar" \
-f deployment/container/Dockerfile-backend \
-t docker.io/hiondal/${service}:${environment}-${imageTag} .
podman push docker.io/hiondal/${service}:${environment}-${imageTag}
@@ -124,7 +174,7 @@ podTemplate(
stage('Update Kustomize & Deploy') {
container('kubectl') {
sh """
# Kustomize 설치
# Kustomize 설치 (sudo 없이 사용자 디렉토리에 설치)
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
mkdir -p \$HOME/bin
mv kustomize \$HOME/bin/
@@ -133,12 +183,12 @@ podTemplate(
# 환경별 디렉토리로 이동
cd deployment/cicd/kustomize/overlays/${environment}
# 서비스 목록 정의
# 서비스 목록 정의 (공백으로 구분)
services="api-gateway user-service bill-service product-service kos-mock"
# 이미지 태그 업데이트
for service in \$services; do
\$HOME/bin/kustomize edit set image docker.io/hiondal/\$service:${environment}-${imageTag}
\$HOME/bin/kustomize edit set image docker.io/hiondal/\$service=docker.io/hiondal/\$service:${environment}-${imageTag}
done
# 매니페스트 적용
@@ -147,15 +197,17 @@ podTemplate(
# 배포 상태 확인
echo "Waiting for deployments to be ready..."
for service in \$services; do
kubectl -n ${props.namespace} wait --for=condition=available deployment/\$service --timeout=300s || echo "Timeout waiting for \$service"
kubectl -n ${props.namespace} wait --for=condition=available deployment/\$service --timeout=300s
done
"""
}
}
// 파이프라인 완료 로그 (Scripted Pipeline 방식)
stage('Pipeline Complete') {
echo "🧹 Pipeline completed. Pod cleanup handled by Jenkins Kubernetes Plugin."
// 성공/실패 여부 로깅
if (currentBuild.result == null || currentBuild.result == 'SUCCESS') {
echo "✅ Pipeline completed successfully!"
} else {