mirror of
https://github.com/cna-bootcamp/lifesub.git
synced 2025-12-06 16:16:22 +00:00
argocd
This commit is contained in:
parent
9d33ba7f3d
commit
22f3d384d3
9
.github/workflows/cicd.yaml
vendored
9
.github/workflows/cicd.yaml
vendored
@ -1,10 +1,9 @@
|
||||
name: Backend CI/CD Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
# Temporarily disabled
|
||||
# on:
|
||||
# push:
|
||||
# branches: [ k8s ]
|
||||
|
||||
env:
|
||||
JAVA_VERSION: '21'
|
||||
|
||||
123
deployment/Jenkinsfile_ArgoCD
Normal file
123
deployment/Jenkinsfile_ArgoCD
Normal file
@ -0,0 +1,123 @@
|
||||
def PIPELINE_ID = "${env.BUILD_NUMBER}"
|
||||
|
||||
def getImageTag() {
|
||||
def dateFormat = new java.text.SimpleDateFormat('yyyyMMddHHmmss')
|
||||
def currentDate = new Date()
|
||||
return dateFormat.format(currentDate)
|
||||
}
|
||||
|
||||
podTemplate(
|
||||
label: "${PIPELINE_ID}",
|
||||
serviceAccount: 'jenkins',
|
||||
containers: [
|
||||
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/git:latest', command: 'cat', ttyEnabled: true)
|
||||
],
|
||||
volumes: [
|
||||
emptyDirVolume(mountPath: '/home/gradle/.gradle', memory: false),
|
||||
emptyDirVolume(mountPath: '/run/podman', memory: false)
|
||||
]
|
||||
) {
|
||||
node(PIPELINE_ID) {
|
||||
def props
|
||||
def imageTag = getImageTag()
|
||||
def services = ['member', 'mysub', 'recommend']
|
||||
def manifestRepo = 'https://github.com/cna-bootcamp/lifesub-manifest.git'
|
||||
def manifestBranch = 'main'
|
||||
|
||||
stage("Get Source") {
|
||||
checkout scm
|
||||
props = readProperties file: "deployment/deploy_env_vars"
|
||||
}
|
||||
|
||||
stage('Build Applications') {
|
||||
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'''
|
||||
|
||||
sh """
|
||||
# TestContainers 설정
|
||||
mkdir -p member/src/test/resources mysub-infra/src/test/resources recommend/src/test/resources
|
||||
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
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build & Push Images') {
|
||||
container('podman') {
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'acr-credentials',
|
||||
usernameVariable: 'USERNAME',
|
||||
passwordVariable: 'PASSWORD'
|
||||
)]) {
|
||||
sh "podman login ${props.registry} --username \$USERNAME --password \$PASSWORD"
|
||||
|
||||
services.each { service ->
|
||||
def buildDir = service == 'mysub' ? 'mysub-infra' : service
|
||||
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 \
|
||||
-t ${props.registry}/${props.image_org}/${service}:${imageTag} .
|
||||
|
||||
podman push ${props.registry}/${props.image_org}/${service}:${imageTag}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Update Manifests') {
|
||||
container('git') {
|
||||
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"
|
||||
|
||||
# Clone manifest repository
|
||||
git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/cna-bootcamp/lifesub-manifest.git
|
||||
cd lifesub-manifest
|
||||
|
||||
# Update image tags in deployment files
|
||||
for service in ${services.join(' ')}; do
|
||||
sed -i 's|image: ${props.registry}/${props.image_org}/'\$service':.*|image: ${props.registry}/${props.image_org}/'\$service':${imageTag}|' lifesub/deployments/\$service-deployment.yaml
|
||||
done
|
||||
|
||||
# Commit and push changes
|
||||
git add .
|
||||
git commit -m "Update backend services images to ${imageTag}"
|
||||
git push origin ${manifestBranch}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user