refactor: stage 브랜치 제거, main에서 Stage→승인→Production 배포 흐름으로 변경

- main: Stage 자동 배포 → Jenkins 승인(24h) → Production 배포
- stage 브랜치 더 이상 사용 안함
- Production 실패 시 자동 롤백
This commit is contained in:
2026-02-24 13:22:22 +09:00
parent b49f66ed57
commit 4f4fa2dd04

34
Jenkinsfile vendored
View File

@@ -11,12 +11,14 @@ pipeline {
steps { checkout scm }
}
// ── stage → 운영서버 Stage 배포 ──
// ── main → 운영서버 Stage 배포 ──
stage('Deploy Stage') {
when { branch 'stage' }
when { branch 'main' }
steps {
sshagent(credentials: ['deploy-ssh-key']) {
sh """
ssh ${DEPLOY_USER}@211.117.60.189 'mkdir -p /home/webservice/api-stage/releases/${RELEASE_ID}'
rsync -az --delete \
--exclude='.git' \
--exclude='.env' \
@@ -44,12 +46,25 @@ pipeline {
}
}
// ── 운영 배포 승인 ──
stage('Production Approval') {
when { branch 'main' }
steps {
timeout(time: 24, unit: 'HOURS') {
input message: 'Stage 확인 후 운영 배포를 진행하시겠습니까?\nStage API: https://stage-api.sam.it.kr',
ok: '운영 배포 진행'
}
}
}
// ── main → 운영서버 Production 배포 ──
stage('Deploy Production') {
when { branch 'main' }
steps {
sshagent(credentials: ['deploy-ssh-key']) {
sh """
ssh ${DEPLOY_USER}@211.117.60.189 'mkdir -p /home/webservice/api/releases/${RELEASE_ID}'
rsync -az --delete \
--exclude='.git' \
--exclude='.env' \
@@ -82,21 +97,18 @@ pipeline {
}
post {
success { echo '✅ api 배포 완료 (' + env.BRANCH_NAME + ')' }
success { echo "✅ api 배포 완료 (${env.BRANCH_NAME})" }
failure {
echo '❌ api 배포 실패 (' + env.BRANCH_NAME + ')'
echo "❌ api 배포 실패 (${env.BRANCH_NAME})"
script {
if (env.BRANCH_NAME in ['main', 'stage']) {
def baseDir = env.BRANCH_NAME == 'main'
? '/home/webservice/api'
: '/home/webservice/api-stage'
if (env.BRANCH_NAME == 'main') {
sshagent(credentials: ['deploy-ssh-key']) {
sh """
ssh ${DEPLOY_USER}@211.117.60.189 '
PREV=\$(ls -1dt ${baseDir}/releases/*/ | sed -n "2p" | xargs basename) &&
[ -n "\$PREV" ] && ln -sfn ${baseDir}/releases/\$PREV ${baseDir}/current &&
PREV=\$(ls -1dt /home/webservice/api/releases/*/ | sed -n "2p" | xargs basename 2>/dev/null) &&
[ -n "\$PREV" ] && ln -sfn /home/webservice/api/releases/\$PREV /home/webservice/api/current &&
sudo systemctl reload php8.4-fpm
'
' || true
"""
}
}