This commit is contained in:
hiondal
2025-04-09 12:32:48 +09:00
47 changed files with 430 additions and 233 deletions
+50 -9
View File
@@ -54,16 +54,16 @@ podTemplate(
}
}
stage('Build Applications') {
stage('Build Applications & SonarQube Analysis') {
container('podman') {
sh 'podman system service -t 0 unix:///run/podman/podman.sock & sleep 2'
}
container('gradle') {
def testContainersConfig = '''docker.client.strategy=org.testcontainers.dockerclient.UnixSocketClientProviderStrategy
docker.host=unix:///run/podman/podman.sock
ryuk.container.privileged=true
testcontainers.reuse.enable=true'''
docker.host=unix:///run/podman/podman.sock
ryuk.container.privileged=true
testcontainers.reuse.enable=true'''
sh """
# TestContainers 설정
@@ -71,11 +71,51 @@ podTemplate(
echo '${testContainersConfig}' > member/src/test/resources/testcontainers.properties
echo '${testContainersConfig}' > mysub-infra/src/test/resources/testcontainers.properties
echo '${testContainersConfig}' > recommend/src/test/resources/testcontainers.properties
# 빌드 실행
chmod +x gradlew
./gradlew clean :member:build :mysub-infra:build :recommend:build
"""
// Member 서비스 빌드 및 SonarQube 분석
withSonarQubeEnv('SonarQube') {
sh """
chmod +x gradlew
# 빌드 실행
./gradlew :member:build :mysub-infra:build :recommend:build -x test
# Member 서비스
./gradlew :member:test :member:jacocoTestReport :member:sonar \
-Dsonar.projectKey=lifesub-member \
-Dsonar.projectName=lifesub-member \
-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/**
# Recommend 서비스
./gradlew :recommend:test :recommend:jacocoTestReport :recommend:sonar \
-Dsonar.projectKey=lifesub-recommend \
-Dsonar.projectName=lifesub-recommend \
-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/**
# Mysub 서비스 (biz & infra 구조)
./gradlew :mysub-infra:test :mysub-infra:jacocoTestReport :mysub-infra:sonar \
-Dsonar.projectKey=lifesub-mysub \
-Dsonar.projectName=lifesub-mysub \
-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/**
"""
}
}
}
stage('Quality Gate') {
timeout(time: 10, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
@@ -143,4 +183,5 @@ podTemplate(
}
}
}
}
}
+102 -64
View File
@@ -10,43 +10,54 @@ podTemplate(
label: "${PIPELINE_ID}",
serviceAccount: 'jenkins',
containers: [
containerTemplate(name: 'podman',
image: "mgoltzsche/podman",
ttyEnabled: true,
command: 'cat',
privileged: true),
containerTemplate(name: 'podman', image: "mgoltzsche/podman", ttyEnabled: true, command: 'cat', privileged: true),
containerTemplate(name: 'gradle',
image: 'gradle:jdk17',
ttyEnabled: true,
command: 'cat',
envVars: [
envVar(key: 'DOCKER_HOST', value: 'unix:///run/podman/podman.sock'),
envVar(key: 'TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE', value: '/run/podman/podman.sock'),
envVar(key: 'TESTCONTAINERS_RYUK_DISABLED', value: 'true')
]),
containerTemplate(name: 'git',
image: 'alpine:3.19',
command: 'cat',
ttyEnabled: true)
image: 'gradle:jdk17',
ttyEnabled: true,
command: 'cat',
envVars: [
envVar(key: 'DOCKER_HOST', value: 'unix:///run/podman/podman.sock'),
envVar(key: 'TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE', value: '/run/podman/podman.sock'),
envVar(key: 'TESTCONTAINERS_RYUK_DISABLED', value: 'true')
]),
containerTemplate(name: 'azure-cli', image: 'hiondal/azure-kubectl:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'envsubst', image: "hiondal/envsubst", command: 'sleep', args: '1h'),
containerTemplate(name: 'git', image: 'alpine/git:latest', command: 'cat', ttyEnabled: true)
],
volumes: [
emptyDirVolume(mountPath: '/home/gradle/.gradle', memory: false),
emptyDirVolume(mountPath: '/root/.azure', memory: false),
emptyDirVolume(mountPath: '/run/podman', memory: false)
]
) {
node(PIPELINE_ID) {
def props
def imageTag = getImageTag()
def manifest = "deploy.yaml"
def namespace
def services = ['member', 'mysub', 'recommend']
def manifestRepo = 'cna-bootcamp/lifesub-manifest'
def manifestBranch = 'main'
def MANIFEST_REPO = "https://github.com/cna-bootcamp/lifesub-manifest.git"
def MANIFEST_BRANCH = "main"
stage("Get Source") {
checkout scm
props = readProperties file: "deployment/deploy_env_vars"
namespace = "${props.namespace}"
}
stage('Build Applications') {
stage("Setup AKS") {
container('azure-cli') {
withCredentials([azureServicePrincipal('azure-credentials')]) {
sh """
az login --service-principal -u \$AZURE_CLIENT_ID -p \$AZURE_CLIENT_SECRET -t \$AZURE_TENANT_ID
az aks get-credentials --resource-group ictcoe-edu --name ${props.teamid}-aks --overwrite-existing
kubectl create namespace ${namespace} --dry-run=client -o yaml | kubectl apply -f -
"""
}
}
}
stage('Build Applications & SonarQube Analysis') {
container('podman') {
sh 'podman system service -t 0 unix:///run/podman/podman.sock & sleep 2'
}
@@ -63,11 +74,50 @@ testcontainers.reuse.enable=true'''
echo '${testContainersConfig}' > member/src/test/resources/testcontainers.properties
echo '${testContainersConfig}' > mysub-infra/src/test/resources/testcontainers.properties
echo '${testContainersConfig}' > recommend/src/test/resources/testcontainers.properties
# 빌드 실행
chmod +x gradlew
./gradlew clean :member:build :mysub-infra:build :recommend:build
"""
// Member 서비스 빌드 및 SonarQube 분석
withSonarQubeEnv('SonarQube') {
sh """
chmod +x gradlew
# 빌드 실행
./gradlew :member:build :mysub-infra:build :recommend:build -x test
# Member 서비스
./gradlew :member:test :member:jacocoTestReport :member:sonar \
-Dsonar.projectKey=lifesub-member \
-Dsonar.projectName=lifesub-member \
-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/**
# Recommend 서비스
./gradlew :recommend:test :recommend:jacocoTestReport :recommend:sonar \
-Dsonar.projectKey=lifesub-recommend \
-Dsonar.projectName=lifesub-recommend \
-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/**
# Mysub 서비스 (biz & infra 구조)
./gradlew :mysub-infra:test :mysub-infra:jacocoTestReport :mysub-infra:sonar \
-Dsonar.projectKey=lifesub-mysub \
-Dsonar.projectName=lifesub-mysub \
-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/**
"""
}
}
}
stage('Quality Gate') {
timeout(time: 10, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
@@ -85,10 +135,10 @@ testcontainers.reuse.enable=true'''
def jarFile = service == 'mysub' ? 'mysub.jar' : "${service}.jar"
sh """
podman build \\
--build-arg BUILD_LIB_DIR="${buildDir}/build/libs" \\
--build-arg ARTIFACTORY_FILE="${jarFile}" \\
-f deployment/Dockerfile \\
podman build \
--build-arg BUILD_LIB_DIR="${buildDir}/build/libs" \
--build-arg ARTIFACTORY_FILE="${jarFile}" \
-f deployment/Dockerfile \
-t ${props.registry}/${props.image_org}/${service}:${imageTag} .
podman push ${props.registry}/${props.image_org}/${service}:${imageTag}
@@ -98,47 +148,35 @@ testcontainers.reuse.enable=true'''
}
}
stage('Update Manifests') {
stage('Update Manifest Repository') {
container('git') {
// git과 yq 설치
sh '''
apk add --no-cache git curl
curl -L https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_amd64 -o /usr/local/bin/yq
chmod +x /usr/local/bin/yq
'''
withCredentials([usernamePassword(
credentialsId: 'github-credentials',
usernameVariable: 'GIT_USERNAME',
passwordVariable: 'GIT_PASSWORD'
)]) {
sh '''
git config --global user.email "jenkins@example.com"
git config --global user.name "Jenkins"
'''
// 임시 디렉토리 생성
sh "mkdir -p /tmp/manifests"
// Clone manifest repository
withCredentials([usernamePassword(credentialsId: 'github-credentials', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
sh """
rm -rf lifesub-manifest
#git clone https://oauth2:${GIT_PASSWORD}@github.com/${manifestRepo}.git
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${manifestRepo}.git
git config --global user.email "jenkins@example.com"
git config --global user.name "Jenkins Pipeline"
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/cna-bootcamp/lifesub-manifest.git /tmp/manifests
cd /tmp/manifests
# Update image tags in the appropriate YAML files
for service in ${services.join(' ')}; do
# 백엔드 서비스 이미지 태그 업데이트
if [ -f lifesub/deployments/\${service}-deployment.yaml ]; then
sed -i "s|image: ${props.registry}/${props.image_org}/\${service}:.*|image: ${props.registry}/${props.image_org}/\${service}:${imageTag}|g" lifesub/deployments/\${service}-deployment.yaml
fi
done
# Commit and push changes
git add .
git commit -m "Update backend service image tags to ${imageTag}" || true
git push
"""
dir('lifesub-manifest') {
services.each { service ->
def imagePath = "${props.registry}/${props.image_org}/${service}:${imageTag}"
sh """
yq -i '.spec.template.spec.containers[0].image = "${imagePath}"' lifesub/deployments/${service}-deployment.yaml
"""
}
sh """
git add .
git diff-index --quiet HEAD || git commit -m "Update backend services images to ${imageTag}"
git push origin ${manifestBranch}
"""
}
}
}
}
}
}
}
+38 -1
View File
@@ -306,4 +306,41 @@ spec:
ports:
- port: 80
targetPort: 8083
type: ClusterIP
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: lifesub
namespace: ${namespace}
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /member(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: member
port:
number: 80
- path: /mysub(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: mysub
port:
number: 80
- path: /recommend(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: recommend
port:
number: 80
+2 -2
View File
@@ -8,8 +8,8 @@ registry=unicorncr.azurecr.io
image_org=lifesub
# Application Settings
replicas=2
allowed_origins=http://4.230.156.229
replicas=1
allowed_origins=http://20.214.113.12
# Security Settings
jwt_secret_key=8O2HQ13etL2BWZvYOiWsJ5uWFoLi6NBUG8divYVoCgtHVvlk3dqRksMl16toztDUeBTSIuOOPvHIrYq11G2BwQ
@@ -5,4 +5,8 @@ metadata:
data:
JPA_DDL_AUTO: update
JPA_SHOW_SQL: "true"
<<<<<<< HEAD
ALLOWED_ORIGINS: "http://localhost:18080,http://localhost:18081,http://20.249.184.6"
=======
ALLOWED_ORIGINS: "http://localhost:18080,http://localhost:18081,http://20.214.113.12"
>>>>>>> 1ea06faa5d92eae36ec9d161158eb1314eaff732
@@ -55,4 +55,4 @@ spec:
path: /actuator/health/readiness
port: 8082
initialDelaySeconds: 60
periodSeconds: 15
periodSeconds: 15