fix: Jenkinsfile
This commit is contained in:
parent
c2298b081c
commit
7292d99335
183
deployment/Jenkinsfile
vendored
183
deployment/Jenkinsfile
vendored
@ -1,140 +1,131 @@
|
||||
pipeline {
|
||||
agent {
|
||||
kubernetes {
|
||||
yaml """
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
containers:
|
||||
- name: podman
|
||||
image: quay.io/podman/stable:latest
|
||||
command:
|
||||
- cat
|
||||
tty: true
|
||||
securityContext:
|
||||
privileged: true
|
||||
- name: envsubst
|
||||
image: bhgedigital/envsubst
|
||||
command:
|
||||
- cat
|
||||
tty: true
|
||||
- name: azure-cli
|
||||
image: mcr.microsoft.com/azure-cli:latest
|
||||
command:
|
||||
- cat
|
||||
tty: true
|
||||
"""
|
||||
}
|
||||
}
|
||||
// deployment/Jenkinsfile
|
||||
def PIPELINE_ID = "${env.BUILD_NUMBER}"
|
||||
|
||||
environment {
|
||||
// 빌드 정보
|
||||
imageTag = sh(script: "echo ${BUILD_NUMBER}", returnStdout: true).trim()
|
||||
manifest = "deploy.yaml"
|
||||
}
|
||||
def getImageTag() {
|
||||
def dateFormat = new java.text.SimpleDateFormat('yyyyMMddHHmmss')
|
||||
def currentDate = new Date()
|
||||
return dateFormat.format(currentDate)
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
podTemplate(
|
||||
label: "${PIPELINE_ID}",
|
||||
serviceAccount: 'jenkins',
|
||||
containers: [
|
||||
containerTemplate(name: 'node', image: 'node:20-slim', ttyEnabled: true, command: 'cat'),
|
||||
containerTemplate(name: 'podman', image: "mgoltzsche/podman", ttyEnabled: true, command: 'cat', privileged: true),
|
||||
containerTemplate(name: 'azure-cli', image: 'hiondal/azure-kubectl:latest', command: 'cat', ttyEnabled: true),
|
||||
containerTemplate(name: 'envsubst', image: "hiondal/envsubst", command: 'sleep', args: '1h')
|
||||
],
|
||||
volumes: [
|
||||
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
|
||||
|
||||
stage("Get Source") {
|
||||
checkout scm
|
||||
}
|
||||
props = readProperties file: "deployment/deploy_env_vars"
|
||||
namespace = "${props.namespace}"
|
||||
|
||||
echo "Registry: ${props.registry}"
|
||||
echo "Image Org: ${props.image_org}"
|
||||
echo "Image Tag: ${imageTag}"
|
||||
}
|
||||
|
||||
stage('Load Deploy Variables') {
|
||||
steps {
|
||||
script {
|
||||
// deploy_env_vars 파일에서 환경변수 로드
|
||||
if (fileExists('deploy_env_vars')) {
|
||||
def envVars = readFile('deploy_env_vars').trim()
|
||||
envVars.split('\n').each { line ->
|
||||
if (line.contains('=')) {
|
||||
def (key, value) = line.split('=', 2)
|
||||
env."${key}" = value
|
||||
echo "Loaded: ${key} = ${value}"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error "deploy_env_vars 파일이 없습니다!"
|
||||
}
|
||||
|
||||
// 이미지 경로 설정
|
||||
env.imagePath = "${env.REGISTRY}/${env.IMAGE_ORG}/smarketing-frontend:${imageTag}"
|
||||
echo "Image Path: ${env.imagePath}"
|
||||
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 rg-digitalgarage-02 --name aks-digitalgarage-02 --overwrite-existing
|
||||
kubectl create namespace ${namespace} --dry-run=client -o yaml | kubectl apply -f -
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build & Push Image') {
|
||||
container('podman') {
|
||||
steps {
|
||||
script {
|
||||
sh 'podman system service -t 0 unix:///run/podman/podman.sock & sleep 2'
|
||||
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'acr-credentials',
|
||||
usernameVariable: 'ACR_USERNAME',
|
||||
passwordVariable: 'ACR_PASSWORD'
|
||||
)]) {
|
||||
def imagePath = "${props.registry}/${props.image_org}/smarketing-frontend:${imageTag}"
|
||||
|
||||
sh """
|
||||
echo "=========================================="
|
||||
echo "Building smarketing-frontend"
|
||||
echo "Image Tag: ${imageTag}"
|
||||
echo "Image Path: ${imagePath}"
|
||||
echo "=========================================="
|
||||
|
||||
# ACR 로그인
|
||||
echo \$ACR_PASSWORD | podman login ${props.registry} --username \$ACR_USERNAME --password-stdin
|
||||
|
||||
# Docker 이미지 빌드
|
||||
podman build \\
|
||||
--build-arg PROJECT_FOLDER="." \\
|
||||
--build-arg REACT_APP_AUTH_URL="${env.AUTH_URL}" \\
|
||||
--build-arg REACT_APP_MEMBER_URL="${env.MEMBER_URL}" \\
|
||||
--build-arg REACT_APP_STORE_URL="${env.STORE_URL}" \\
|
||||
--build-arg REACT_APP_CONTENT_URL="${env.CONTENT_URL}" \\
|
||||
--build-arg REACT_APP_RECOMMEND_URL="${env.RECOMMEND_URL}" \\
|
||||
--build-arg REACT_APP_AUTH_URL="${props.auth_url}" \\
|
||||
--build-arg REACT_APP_MEMBER_URL="${props.member_url}" \\
|
||||
--build-arg REACT_APP_STORE_URL="${props.store_url}" \\
|
||||
--build-arg REACT_APP_CONTENT_URL="${props.content_url}" \\
|
||||
--build-arg REACT_APP_RECOMMEND_URL="${props.recommend_url}" \\
|
||||
--build-arg BUILD_FOLDER="deployment/container" \\
|
||||
--build-arg EXPORT_PORT="${env.EXPORT_PORT}" \\
|
||||
--build-arg EXPORT_PORT="${props.export_port}" \\
|
||||
-f deployment/container/Dockerfile-smarketing-frontend \\
|
||||
-t ${env.imagePath} .
|
||||
-t ${imagePath} .
|
||||
|
||||
podman push ${env.imagePath}
|
||||
# 이미지 푸시
|
||||
podman push ${imagePath}
|
||||
|
||||
echo "Image pushed successfully: ${imagePath}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Generate & Apply Manifest') {
|
||||
container('envsubst') {
|
||||
steps {
|
||||
def imagePath = "${props.registry}/${props.image_org}/smarketing-frontend:${imageTag}"
|
||||
|
||||
sh """
|
||||
export namespace=${env.NAMESPACE}
|
||||
export smarketing_frontend_image_path=${env.imagePath}
|
||||
export replicas=${env.REPLICAS}
|
||||
export export_port=${env.EXPORT_PORT}
|
||||
export ingress_host=${env.INGRESS_HOST}
|
||||
export resources_requests_cpu=${env.RESOURCES_REQUESTS_CPU}
|
||||
export resources_requests_memory=${env.RESOURCES_REQUESTS_MEMORY}
|
||||
export resources_limits_cpu=${env.RESOURCES_LIMITS_CPU}
|
||||
export resources_limits_memory=${env.RESOURCES_LIMITS_MEMORY}
|
||||
export namespace=${namespace}
|
||||
export smarketing_frontend_image_path=${imagePath}
|
||||
export replicas=${props.replicas}
|
||||
export export_port=${props.export_port}
|
||||
export ingress_host=${props.ingress_host}
|
||||
export resources_requests_cpu=${props.resources_requests_cpu}
|
||||
export resources_requests_memory=${props.resources_requests_memory}
|
||||
export resources_limits_cpu=${props.resources_limits_cpu}
|
||||
export resources_limits_memory=${props.resources_limits_memory}
|
||||
|
||||
envsubst < deployment/${manifest}.template > deployment/${manifest}
|
||||
echo "Generated manifest file:"
|
||||
cat deployment/${manifest}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
container('azure-cli') {
|
||||
steps {
|
||||
sh """
|
||||
kubectl apply -f deployment/${manifest}
|
||||
|
||||
echo "Waiting for deployment to be ready..."
|
||||
kubectl -n ${env.NAMESPACE} wait --for=condition=available deployment/smarketing-frontend --timeout=300s
|
||||
kubectl -n ${namespace} wait --for=condition=available deployment/smarketing-frontend --timeout=300s
|
||||
|
||||
echo "Deployment completed successfully!"
|
||||
kubectl -n ${env.NAMESPACE} get pods -l app=smarketing-frontend
|
||||
kubectl -n ${env.NAMESPACE} get svc smarketing-frontend-service
|
||||
kubectl -n ${namespace} get pods -l app=smarketing-frontend
|
||||
kubectl -n ${namespace} get svc smarketing-frontend-service
|
||||
kubectl -n ${namespace} get ingress
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
cleanWs()
|
||||
}
|
||||
success {
|
||||
echo "✅ smarketing-frontend 배포가 성공적으로 완료되었습니다!"
|
||||
}
|
||||
failure {
|
||||
echo "❌ smarketing-frontend 배포 중 오류가 발생했습니다."
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user