Add CI/CD

This commit is contained in:
Ubuntu 2025-05-28 13:02:57 +00:00
parent b60030173b
commit f3a6d06577
3 changed files with 51 additions and 27 deletions

View File

@ -37,14 +37,14 @@ podTemplate(
stage('Code Analysis & Quality Gate') { stage('Code Analysis & Quality Gate') {
container('node') { container('node') {
sh "npm install" sh "npm install"
sh "npm test -- --coverage --passWithNoTests" //test code 없어도 통과되게 함 sh "npm test -- --coverage --passWithNoTests"
} }
container('sonar-scanner') { container('sonar-scanner') {
withSonarQubeEnv('SonarQube') { withSonarQubeEnv('SonarQube') {
sh """ sh """
${sonarScannerHome}/bin/sonar-scanner \ ${sonarScannerHome}/bin/sonar-scanner \
-Dsonar.projectKey=lifesub-web \ -Dsonar.projectKey=lifesub-web-lifesub-web-dg0400 \
-Dsonar.sources=src \ -Dsonar.sources=src \
-Dsonar.tests=src \ -Dsonar.tests=src \
-Dsonar.test.inclusions=src/**/*.test.js,src/**/*.test.jsx \ -Dsonar.test.inclusions=src/**/*.test.js,src/**/*.test.jsx \
@ -66,7 +66,7 @@ podTemplate(
withCredentials([azureServicePrincipal('azure-credentials')]) { withCredentials([azureServicePrincipal('azure-credentials')]) {
sh """ sh """
az login --service-principal -u \$AZURE_CLIENT_ID -p \$AZURE_CLIENT_SECRET -t \$AZURE_TENANT_ID 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 az aks get-credentials --resource-group rg-digitalgarage-01 --name aks-digitalgarage-01 --overwrite-existing
kubectl create namespace ${namespace} --dry-run=client -o yaml | kubectl apply -f - kubectl create namespace ${namespace} --dry-run=client -o yaml | kubectl apply -f -
""" """
} }
@ -87,12 +87,9 @@ podTemplate(
podman build \ podman build \
--build-arg PROJECT_FOLDER="." \ --build-arg PROJECT_FOLDER="." \
--build-arg REACT_APP_MEMBER_URL="${props.react_app_member_url}" \ --build-arg BUILD_FOLDER="deployment/container" \
--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}" \ --build-arg EXPORT_PORT="${props.export_port}" \
-f deployment/Dockerfile-lifesub-web \ -f deployment/container/Dockerfile-lifesub-web \
-t ${imagePath} . -t ${imagePath} .
podman push ${imagePath} podman push ${imagePath}
@ -114,6 +111,7 @@ podTemplate(
export resources_limits_memory=${props.resources_limits_memory} export resources_limits_memory=${props.resources_limits_memory}
envsubst < deployment/${manifest}.template > deployment/${manifest} envsubst < deployment/${manifest}.template > deployment/${manifest}
echo "Generated manifest file:"
cat deployment/${manifest} cat deployment/${manifest}
""" """
} }
@ -126,10 +124,11 @@ podTemplate(
kubectl -n ${namespace} wait --for=condition=available deployment/lifesub-web --timeout=300s kubectl -n ${namespace} wait --for=condition=available deployment/lifesub-web --timeout=300s
echo "Waiting for service external IP..." echo "Waiting for service external IP..."
while [[ -z \$(kubectl -n ${namespace} get svc lifesub-web -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ]]; do while [[ -z \$(kubectl -n ${namespace} get svc lifesub-web-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ]]; do
sleep 5 sleep 5
echo "Still waiting for external IP assignment..."
done done
echo "Service external IP: \$(kubectl -n ${namespace} get svc lifesub-web -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" echo "Service external IP: \$(kubectl -n ${namespace} get svc lifesub-web-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
""" """
} }
} }

View File

@ -1,9 +1,26 @@
# Frontend Deployment # ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: frontend-config
namespace: ${namespace}
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'
};
---
# Deployment
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: lifesub-web name: lifesub-web
namespace: ${namespace} namespace: ${namespace}
labels:
app: lifesub-web
spec: spec:
replicas: ${replicas} replicas: ${replicas}
selector: selector:
@ -14,6 +31,8 @@ spec:
labels: labels:
app: lifesub-web app: lifesub-web
spec: spec:
imagePullSecrets:
- name: acr-secret
containers: containers:
- name: lifesub-web - name: lifesub-web
image: ${lifesub_web_image_path} image: ${lifesub_web_image_path}
@ -27,18 +46,29 @@ spec:
limits: limits:
cpu: ${resources_limits_cpu} cpu: ${resources_limits_cpu}
memory: ${resources_limits_memory} memory: ${resources_limits_memory}
volumeMounts:
- name: runtime-config
mountPath: /usr/share/nginx/html/runtime-env.js
subPath: runtime-env.js
volumes:
- name: runtime-config
configMap:
name: frontend-config
--- ---
# Frontend Service # Service
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: lifesub-web name: lifesub-web-service
namespace: ${namespace} namespace: ${namespace}
spec: labels:
selector:
app: lifesub-web app: lifesub-web
spec:
type: LoadBalancer
ports: ports:
- port: 80 - port: 80
targetPort: ${export_port} targetPort: ${export_port}
type: LoadBalancer protocol: TCP
selector:
app: lifesub-web

View File

@ -1,21 +1,16 @@
# Team Settings # Team Settings
teamid=unicorn teamid=dg0400
root_project=lifesub-web root_project=lifesub-web
namespace=unicorn-lifesub-ns namespace=dg0400-lifesub-ns
# Container Registry Settings # Container Registry Settings
registry=unicorncr.azurecr.io registry=acrdigitalgarage01.azurecr.io
image_org=lifesub image_org=dg0400
# Application Settings # Application Settings
replicas=1 replicas=1
export_port=18080 export_port=18080
# Backend Service URLs
react_app_member_url=http://20.249.205.95/member
react_app_mysub_url=http://20.249.205.95/mysub
react_app_recommend_url=http://20.249.205.95/recommend
# Resource Settings # Resource Settings
resources_requests_cpu=256m resources_requests_cpu=256m
resources_requests_memory=256Mi resources_requests_memory=256Mi