mirror of
https://github.com/cna-bootcamp/lifesub.git
synced 2026-01-21 19:16:23 +00:00
add github aciton
This commit is contained in:
parent
9c55bc6905
commit
2579af4dbb
9
.github/workflows/cicd.yaml
vendored
9
.github/workflows/cicd.yaml
vendored
@ -207,8 +207,10 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "IMAGE_TAG=${{ needs.build.outputs.image_tag }}" >> $GITHUB_ENV
|
echo "IMAGE_TAG=${{ needs.build.outputs.image_tag }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# Azure CLI 설치 단계 수정
|
||||||
- name: Install Azure CLI
|
- name: Install Azure CLI
|
||||||
uses: azure/setup-azure-cli@v1
|
run: |
|
||||||
|
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
|
||||||
|
|
||||||
- name: Azure Login
|
- name: Azure Login
|
||||||
uses: azure/login@v1
|
uses: azure/login@v1
|
||||||
@ -226,6 +228,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
kubectl create namespace ${{ env.namespace }} --dry-run=client -o yaml | kubectl apply -f -
|
kubectl create namespace ${{ env.namespace }} --dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
|
- name: Install envsubst
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y gettext-base
|
||||||
|
|
||||||
- name: Generate Kubernetes manifest
|
- name: Generate Kubernetes manifest
|
||||||
run: |
|
run: |
|
||||||
# Set environment variables for the deployment template
|
# Set environment variables for the deployment template
|
||||||
|
|||||||
@ -10,11 +10,7 @@ podTemplate(
|
|||||||
label: "${PIPELINE_ID}",
|
label: "${PIPELINE_ID}",
|
||||||
serviceAccount: 'jenkins',
|
serviceAccount: 'jenkins',
|
||||||
containers: [
|
containers: [
|
||||||
containerTemplate(name: 'podman',
|
containerTemplate(name: 'podman', image: "mgoltzsche/podman", ttyEnabled: true, command: 'cat', privileged: true),
|
||||||
image: "mgoltzsche/podman",
|
|
||||||
ttyEnabled: true,
|
|
||||||
command: 'cat',
|
|
||||||
privileged: true),
|
|
||||||
containerTemplate(name: 'gradle',
|
containerTemplate(name: 'gradle',
|
||||||
image: 'gradle:jdk17',
|
image: 'gradle:jdk17',
|
||||||
ttyEnabled: true,
|
ttyEnabled: true,
|
||||||
@ -24,29 +20,44 @@ podTemplate(
|
|||||||
envVar(key: 'TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE', value: '/run/podman/podman.sock'),
|
envVar(key: 'TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE', value: '/run/podman/podman.sock'),
|
||||||
envVar(key: 'TESTCONTAINERS_RYUK_DISABLED', value: 'true')
|
envVar(key: 'TESTCONTAINERS_RYUK_DISABLED', value: 'true')
|
||||||
]),
|
]),
|
||||||
containerTemplate(name: 'git',
|
containerTemplate(name: 'azure-cli', image: 'hiondal/azure-kubectl:latest', command: 'cat', ttyEnabled: true),
|
||||||
image: 'alpine:3.19',
|
containerTemplate(name: 'envsubst', image: "hiondal/envsubst", command: 'sleep', args: '1h'),
|
||||||
command: 'cat',
|
containerTemplate(name: 'git', image: 'alpine/git:latest', command: 'cat', ttyEnabled: true)
|
||||||
ttyEnabled: true)
|
|
||||||
],
|
],
|
||||||
volumes: [
|
volumes: [
|
||||||
emptyDirVolume(mountPath: '/home/gradle/.gradle', memory: false),
|
emptyDirVolume(mountPath: '/home/gradle/.gradle', memory: false),
|
||||||
|
emptyDirVolume(mountPath: '/root/.azure', memory: false),
|
||||||
emptyDirVolume(mountPath: '/run/podman', memory: false)
|
emptyDirVolume(mountPath: '/run/podman', memory: false)
|
||||||
]
|
]
|
||||||
) {
|
) {
|
||||||
node(PIPELINE_ID) {
|
node(PIPELINE_ID) {
|
||||||
def props
|
def props
|
||||||
def imageTag = getImageTag()
|
def imageTag = getImageTag()
|
||||||
|
def manifest = "deploy.yaml"
|
||||||
|
def namespace
|
||||||
def services = ['member', 'mysub', 'recommend']
|
def services = ['member', 'mysub', 'recommend']
|
||||||
def manifestRepo = 'cna-bootcamp/lifesub-manifest'
|
def MANIFEST_REPO = "https://github.com/cna-bootcamp/lifesub-manifest.git"
|
||||||
def manifestBranch = 'main'
|
def MANIFEST_BRANCH = "main"
|
||||||
|
|
||||||
stage("Get Source") {
|
stage("Get Source") {
|
||||||
checkout scm
|
checkout scm
|
||||||
props = readProperties file: "deployment/deploy_env_vars"
|
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') {
|
container('podman') {
|
||||||
sh 'podman system service -t 0 unix:///run/podman/podman.sock & sleep 2'
|
sh 'podman system service -t 0 unix:///run/podman/podman.sock & sleep 2'
|
||||||
}
|
}
|
||||||
@ -63,13 +74,52 @@ testcontainers.reuse.enable=true'''
|
|||||||
echo '${testContainersConfig}' > member/src/test/resources/testcontainers.properties
|
echo '${testContainersConfig}' > member/src/test/resources/testcontainers.properties
|
||||||
echo '${testContainersConfig}' > mysub-infra/src/test/resources/testcontainers.properties
|
echo '${testContainersConfig}' > mysub-infra/src/test/resources/testcontainers.properties
|
||||||
echo '${testContainersConfig}' > recommend/src/test/resources/testcontainers.properties
|
echo '${testContainersConfig}' > recommend/src/test/resources/testcontainers.properties
|
||||||
|
"""
|
||||||
|
|
||||||
|
// Member 서비스 빌드 및 SonarQube 분석
|
||||||
|
withSonarQubeEnv('SonarQube') {
|
||||||
|
sh """
|
||||||
|
chmod +x gradlew
|
||||||
|
|
||||||
# 빌드 실행
|
# 빌드 실행
|
||||||
chmod +x gradlew
|
./gradlew :member:build :mysub-infra:build :recommend:build -x test
|
||||||
./gradlew clean :member:build :mysub-infra:build :recommend:build
|
|
||||||
|
# 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}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Build & Push Images') {
|
stage('Build & Push Images') {
|
||||||
container('podman') {
|
container('podman') {
|
||||||
@ -85,10 +135,10 @@ testcontainers.reuse.enable=true'''
|
|||||||
def jarFile = service == 'mysub' ? 'mysub.jar' : "${service}.jar"
|
def jarFile = service == 'mysub' ? 'mysub.jar' : "${service}.jar"
|
||||||
|
|
||||||
sh """
|
sh """
|
||||||
podman build \\
|
podman build \
|
||||||
--build-arg BUILD_LIB_DIR="${buildDir}/build/libs" \\
|
--build-arg BUILD_LIB_DIR="${buildDir}/build/libs" \
|
||||||
--build-arg ARTIFACTORY_FILE="${jarFile}" \\
|
--build-arg ARTIFACTORY_FILE="${jarFile}" \
|
||||||
-f deployment/Dockerfile \\
|
-f deployment/Dockerfile \
|
||||||
-t ${props.registry}/${props.image_org}/${service}:${imageTag} .
|
-t ${props.registry}/${props.image_org}/${service}:${imageTag} .
|
||||||
|
|
||||||
podman push ${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') {
|
container('git') {
|
||||||
// git과 yq 설치
|
// 임시 디렉토리 생성
|
||||||
sh '''
|
sh "mkdir -p /tmp/manifests"
|
||||||
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(
|
// Clone manifest repository
|
||||||
credentialsId: 'github-credentials',
|
withCredentials([usernamePassword(credentialsId: 'github-credentials', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
|
||||||
usernameVariable: 'GIT_USERNAME',
|
sh """
|
||||||
passwordVariable: 'GIT_PASSWORD'
|
|
||||||
)]) {
|
|
||||||
sh '''
|
|
||||||
git config --global user.email "jenkins@example.com"
|
git config --global user.email "jenkins@example.com"
|
||||||
git config --global user.name "Jenkins"
|
git config --global user.name "Jenkins Pipeline"
|
||||||
'''
|
|
||||||
|
|
||||||
sh """
|
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/cna-bootcamp/lifesub-manifest.git /tmp/manifests
|
||||||
rm -rf lifesub-manifest
|
cd /tmp/manifests
|
||||||
#git clone https://oauth2:${GIT_PASSWORD}@github.com/${manifestRepo}.git
|
|
||||||
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${manifestRepo}.git
|
|
||||||
"""
|
|
||||||
|
|
||||||
dir('lifesub-manifest') {
|
# Update image tags in the appropriate YAML files
|
||||||
services.each { service ->
|
for service in ${services.join(' ')}; do
|
||||||
def imagePath = "${props.registry}/${props.image_org}/${service}:${imageTag}"
|
# 백엔드 서비스 이미지 태그 업데이트
|
||||||
sh """
|
if [ -f lifesub/deployments/\${service}.yaml ]; then
|
||||||
yq -i '.spec.template.spec.containers[0].image = "${imagePath}"' lifesub/deployments/${service}-deployment.yaml
|
sed -i "s|image: ${props.registry}/${props.image_org}/\${service}:.*|image: ${props.registry}/${props.image_org}/\${service}:${imageTag}|g" lifesub/deployments/\${service}.yaml
|
||||||
"""
|
fi
|
||||||
}
|
done
|
||||||
|
|
||||||
sh """
|
# Commit and push changes
|
||||||
git add .
|
git add .
|
||||||
git diff-index --quiet HEAD || git commit -m "Update backend services images to ${imageTag}"
|
git commit -m "Update backend service image tags to ${imageTag}" || true
|
||||||
git push origin ${manifestBranch}
|
git push
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user