lifesub-web/deployment/Jenkinsfile_ArgoCD
2025-02-18 04:47:14 +09:00

88 lines
3.7 KiB
Plaintext

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: 'git', image: 'alpine/git:latest', command: 'cat', ttyEnabled: true)
],
volumes: [
emptyDirVolume(mountPath: '/root/.azure', memory: false)
]
) {
node(PIPELINE_ID) {
def props
def imageTag = getImageTag()
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 & 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') {
container('git') {
withCredentials([usernamePassword(
credentialsId: 'github-credentials',
usernameVariable: 'GIT_USERNAME',
passwordVariable: 'GIT_PASSWORD'
)]) {
// Configure Git
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 tag in deployment yaml
sed -i 's|image: ${props.registry}/${props.image_org}/lifesub-web:.*|image: ${props.registry}/${props.image_org}/lifesub-web:${imageTag}|' lifesub-web/deployments/lifesub-web-deployment.yaml
# Commit and push changes
git add .
git commit -m "Update lifesub-web image to ${imageTag}"
git push origin ${manifestBranch}
"""
}
}
}
}
}