From 34335abc929fb1580b4fe2aa19d0c1526cd87512 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 29 May 2025 02:22:44 +0000 Subject: [PATCH] add CI/CD files --- deployment/Jenkinsfile | 4 +- deployment/Jenkinsfile_ArgoCD | 136 -------------------------------- deployment/deploy.yaml.template | 6 +- deployment/deploy_env_vars | 1 + 4 files changed, 6 insertions(+), 141 deletions(-) delete mode 100644 deployment/Jenkinsfile_ArgoCD diff --git a/deployment/Jenkinsfile b/deployment/Jenkinsfile index 9b44e26..42ecce9 100644 --- a/deployment/Jenkinsfile +++ b/deployment/Jenkinsfile @@ -44,7 +44,7 @@ podTemplate( withSonarQubeEnv('SonarQube') { sh """ ${sonarScannerHome}/bin/sonar-scanner \ - -Dsonar.projectKey=lifesub-web-lifesub-web-dg0400 \ + -Dsonar.projectKey=lifesub-web-dg0400 \ -Dsonar.sources=src \ -Dsonar.tests=src \ -Dsonar.test.inclusions=src/**/*.test.js,src/**/*.test.jsx \ @@ -105,6 +105,7 @@ podTemplate( export lifesub_web_image_path=${props.registry}/${props.image_org}/lifesub-web:${imageTag} 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} @@ -126,7 +127,6 @@ podTemplate( echo "Waiting for service external IP..." while [[ -z \$(kubectl -n ${namespace} get svc lifesub-web-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ]]; do sleep 5 - echo "Still waiting for external IP assignment..." done echo "Service external IP: \$(kubectl -n ${namespace} get svc lifesub-web-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" """ diff --git a/deployment/Jenkinsfile_ArgoCD b/deployment/Jenkinsfile_ArgoCD deleted file mode 100644 index d78fced..0000000 --- a/deployment/Jenkinsfile_ArgoCD +++ /dev/null @@ -1,136 +0,0 @@ -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: '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'), - containerTemplate(name: 'sonar-scanner', image: 'sonarsource/sonar-scanner-cli:latest', command: 'cat', ttyEnabled: true), - containerTemplate(name: 'git', image: 'alpine/git:latest', command: 'cat', ttyEnabled: true) - ], - volumes: [ - emptyDirVolume(mountPath: '/root/.azure', memory: false), - emptyDirVolume(mountPath: '/opt/sonar-scanner/.sonar/cache', memory: false) - ] -) { - node(PIPELINE_ID) { - def props - def imageTag = getImageTag() - def manifest = "deploy.yaml" - def namespace - def sonarScannerHome = '/opt/sonar-scanner' - 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('Code Analysis & Quality Gate') { - container('node') { - sh "npm install" - sh "npm test -- --coverage --passWithNoTests" //test code 없어도 통과되게 함 - } - - container('sonar-scanner') { - withSonarQubeEnv('SonarQube') { - sh """ - ${sonarScannerHome}/bin/sonar-scanner \ - -Dsonar.projectKey=lifesub-web \ - -Dsonar.sources=src \ - -Dsonar.tests=src \ - -Dsonar.test.inclusions=src/**/*.test.js,src/**/*.test.jsx \ - -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info - """ - } - } - - timeout(time: 10, unit: 'MINUTES') { - def qg = waitForQualityGate() - if (qg.status != 'OK') { - error "Pipeline aborted due to quality gate failure: ${qg.status}" - } - } - } - - 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 & Push Image') { - container('podman') { - withCredentials([usernamePassword( - credentialsId: 'acr-credentials', - usernameVariable: 'USERNAME', - passwordVariable: 'PASSWORD' - )]) { - def imagePath = "${props.registry}/${props.image_org}/lifesub-web:${imageTag}" - - sh """ - podman login ${props.registry} --username \$USERNAME --password \$PASSWORD - - podman build \ - --build-arg PROJECT_FOLDER="." \ - --build-arg REACT_APP_MEMBER_URL="${props.react_app_member_url}" \ - --build-arg REACT_APP_MYSUB_URL="${props.react_app_mysub_url}" \ - --build-arg REACT_APP_RECOMMEND_URL="${props.react_app_recommend_url}" \ - --build-arg BUILD_FOLDER="deployment" \ - --build-arg EXPORT_PORT="${props.export_port}" \ - -f deployment/Dockerfile-lifesub-web \ - -t ${imagePath} . - - podman push ${imagePath} - """ - } - } - } - - stage('Update Manifest Repository') { - container('git') { - // 임시 디렉토리 생성 - sh "mkdir -p /tmp/manifests" - - // Clone manifest repository - 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 Pipeline" - - git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/cna-bootcamp/lifesub-manifest.git /tmp/manifests - cd /tmp/manifests - - # Update frontend image tag - if [ -f lifesub-web/deployments/lifesub-web-deployment.yaml ]; then - sed -i "s|image: ${props.registry}/${props.image_org}/lifesub-web:.*|image: ${props.registry}/${props.image_org}/lifesub-web:${imageTag}|g" lifesub-web/deployments/lifesub-web-deployment.yaml - fi - - # Commit and push changes - git add . - git commit -m "Update frontend image tag to ${imageTag}" || true - git push - """ - } - } - } - } -} - diff --git a/deployment/deploy.yaml.template b/deployment/deploy.yaml.template index c76abe0..05573c8 100644 --- a/deployment/deploy.yaml.template +++ b/deployment/deploy.yaml.template @@ -7,9 +7,9 @@ metadata: data: runtime-env.js: | window.__runtime_config__ = { - MEMBER_URL: 'http://dg0400.20.214.196.128.nip.io/api/auth', - MYSUB_URL: 'http://dg0400.20.214.196.128.nip.io/api/mysub', - RECOMMEND_URL: 'http://dg0400.20.214.196.128.nip.io/api/recommend' + MEMBER_URL: 'http://${ingress_host}/api/auth', + MYSUB_URL: 'http://${ingress_host}/api/mysub', + RECOMMEND_URL: 'http://${ingress_host}/api/recommend' }; --- diff --git a/deployment/deploy_env_vars b/deployment/deploy_env_vars index 20ac507..64cae28 100644 --- a/deployment/deploy_env_vars +++ b/deployment/deploy_env_vars @@ -10,6 +10,7 @@ image_org=dg0400 # Application Settings replicas=1 export_port=18080 +ingress_host=dg0400.20.214.196.128.nip.io # Resource Settings resources_requests_cpu=256m