Add GitHub Action
This commit is contained in:
parent
b99eb5c3a1
commit
e6c9bffad3
2
.github/workflows/cicd.yaml
vendored
2
.github/workflows/cicd.yaml
vendored
@ -2,7 +2,7 @@ name: Frontend CI/CD Pipeline
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
#branches: [main]
|
||||||
paths:
|
paths:
|
||||||
- '**'
|
- '**'
|
||||||
- '!**.md'
|
- '!**.md'
|
||||||
|
|||||||
@ -10,33 +10,70 @@ podTemplate(
|
|||||||
label: "${PIPELINE_ID}",
|
label: "${PIPELINE_ID}",
|
||||||
serviceAccount: 'jenkins',
|
serviceAccount: 'jenkins',
|
||||||
containers: [
|
containers: [
|
||||||
containerTemplate(name: 'node',
|
containerTemplate(name: 'node', image: 'node:20-slim', ttyEnabled: true, command: 'cat'),
|
||||||
image: 'node:20-slim',
|
containerTemplate(name: 'podman', image: "mgoltzsche/podman", ttyEnabled: true, command: 'cat', privileged: true),
|
||||||
ttyEnabled: true,
|
containerTemplate(name: 'azure-cli', image: 'hiondal/azure-kubectl:latest', command: 'cat', ttyEnabled: true),
|
||||||
command: 'cat'),
|
containerTemplate(name: 'envsubst', image: "hiondal/envsubst", command: 'sleep', args: '1h'),
|
||||||
containerTemplate(name: 'podman',
|
containerTemplate(name: 'sonar-scanner', image: 'sonarsource/sonar-scanner-cli:latest', command: 'cat', ttyEnabled: true),
|
||||||
image: "mgoltzsche/podman",
|
containerTemplate(name: 'git', image: 'alpine/git:latest', command: 'cat', ttyEnabled: true)
|
||||||
ttyEnabled: true,
|
|
||||||
command: 'cat',
|
|
||||||
privileged: true),
|
|
||||||
containerTemplate(name: 'git',
|
|
||||||
image: 'alpine:3.19',
|
|
||||||
command: 'cat',
|
|
||||||
ttyEnabled: true)
|
|
||||||
],
|
],
|
||||||
volumes: [
|
volumes: [
|
||||||
emptyDirVolume(mountPath: '/root/.azure', memory: false)
|
emptyDirVolume(mountPath: '/root/.azure', memory: false),
|
||||||
|
emptyDirVolume(mountPath: '/opt/sonar-scanner/.sonar/cache', memory: false)
|
||||||
]
|
]
|
||||||
) {
|
) {
|
||||||
node(PIPELINE_ID) {
|
node(PIPELINE_ID) {
|
||||||
def props
|
def props
|
||||||
def imageTag = getImageTag()
|
def imageTag = getImageTag()
|
||||||
def manifestRepo = 'cna-bootcamp/lifesub-manifest'
|
def manifest = "deploy.yaml"
|
||||||
def manifestBranch = 'main'
|
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") {
|
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('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') {
|
stage('Build & Push Image') {
|
||||||
@ -51,14 +88,14 @@ podTemplate(
|
|||||||
sh """
|
sh """
|
||||||
podman login ${props.registry} --username \$USERNAME --password \$PASSWORD
|
podman login ${props.registry} --username \$USERNAME --password \$PASSWORD
|
||||||
|
|
||||||
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 REACT_APP_MEMBER_URL="${props.react_app_member_url}" \
|
||||||
--build-arg REACT_APP_MYSUB_URL="${props.react_app_mysub_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 REACT_APP_RECOMMEND_URL="${props.react_app_recommend_url}" \
|
||||||
--build-arg BUILD_FOLDER="deployment" \\
|
--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/Dockerfile-lifesub-web \
|
||||||
-t ${imagePath} .
|
-t ${imagePath} .
|
||||||
|
|
||||||
podman push ${imagePath}
|
podman push ${imagePath}
|
||||||
@ -67,42 +104,32 @@ podTemplate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Update Manifest') {
|
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://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${manifestRepo}.git
|
|
||||||
"""
|
|
||||||
|
|
||||||
dir('lifesub-manifest') {
|
# Update frontend image tag
|
||||||
def imagePath = "${props.registry}/${props.image_org}/lifesub-web:${imageTag}"
|
if [ -f lifesub-web/deployments/lifesub-web.yaml ]; then
|
||||||
sh """
|
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.yaml
|
||||||
yq -i '.spec.template.spec.containers[0].image = "${imagePath}"' lifesub-web/deployments/lifesub-web-deployment.yaml
|
fi
|
||||||
|
|
||||||
|
# Commit and push changes
|
||||||
git add .
|
git add .
|
||||||
git diff-index --quiet HEAD || git commit -m "Update lifesub-web image to ${imageTag}"
|
git commit -m "Update frontend image tag to ${imageTag}" || true
|
||||||
git push origin ${manifestBranch}
|
git push
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user