2026-02-24 08:15:05 +09:00
|
|
|
pipeline {
|
|
|
|
|
agent any
|
|
|
|
|
|
2026-02-25 11:30:57 +09:00
|
|
|
options {
|
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 08:15:05 +09:00
|
|
|
environment {
|
|
|
|
|
DEPLOY_USER = 'hskwon'
|
|
|
|
|
RELEASE_ID = new Date().format('yyyyMMdd_HHmmss')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stages {
|
|
|
|
|
stage('Checkout') {
|
2026-02-24 21:00:05 +09:00
|
|
|
steps {
|
|
|
|
|
checkout scm
|
2026-02-25 12:52:17 +09:00
|
|
|
script {
|
|
|
|
|
env.GIT_COMMIT_MSG = sh(script: "git log -1 --pretty=format:'%s'", returnStdout: true).trim()
|
|
|
|
|
}
|
2026-03-05 11:32:16 +09:00
|
|
|
slackSend channel: '#deploy_api', color: '#439FE0', tokenCredentialId: 'slack-token',
|
2026-02-25 12:52:17 +09:00
|
|
|
message: "🚀 *api* 빌드 시작 (`${env.BRANCH_NAME}`)\n${env.GIT_COMMIT_MSG}\n<${env.BUILD_URL}|빌드 #${env.BUILD_NUMBER}>"
|
2026-02-24 21:00:05 +09:00
|
|
|
}
|
2026-02-24 08:15:05 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 13:22:22 +09:00
|
|
|
// ── main → 운영서버 Stage 배포 ──
|
2026-02-24 08:15:05 +09:00
|
|
|
stage('Deploy Stage') {
|
2026-02-24 13:22:22 +09:00
|
|
|
when { branch 'main' }
|
2026-02-24 08:15:05 +09:00
|
|
|
steps {
|
|
|
|
|
sshagent(credentials: ['deploy-ssh-key']) {
|
|
|
|
|
sh """
|
2026-02-24 13:22:22 +09:00
|
|
|
ssh ${DEPLOY_USER}@211.117.60.189 'mkdir -p /home/webservice/api-stage/releases/${RELEASE_ID}'
|
2026-02-24 08:15:05 +09:00
|
|
|
rsync -az --delete \
|
2026-02-24 17:41:22 +09:00
|
|
|
--exclude='.git' --exclude='.env' \
|
|
|
|
|
--exclude='storage/app' --exclude='storage/logs' \
|
|
|
|
|
--exclude='storage/framework/sessions' --exclude='storage/framework/cache' \
|
2026-02-24 08:15:05 +09:00
|
|
|
. ${DEPLOY_USER}@211.117.60.189:/home/webservice/api-stage/releases/${RELEASE_ID}/
|
|
|
|
|
ssh ${DEPLOY_USER}@211.117.60.189 '
|
|
|
|
|
cd /home/webservice/api-stage/releases/${RELEASE_ID} &&
|
2026-02-24 23:00:32 +09:00
|
|
|
mkdir -p bootstrap/cache storage/framework/{views,cache/data,sessions} storage/logs &&
|
2026-02-27 10:44:54 +09:00
|
|
|
sudo chown -R www-data:webservice storage bootstrap/cache &&
|
|
|
|
|
sudo chmod -R 775 storage bootstrap/cache &&
|
2026-02-24 08:15:05 +09:00
|
|
|
ln -sfn /home/webservice/api-stage/shared/.env .env &&
|
2026-03-03 09:51:07 +09:00
|
|
|
sudo chmod 640 /home/webservice/api-stage/shared/.env &&
|
2026-02-24 08:15:05 +09:00
|
|
|
ln -sfn /home/webservice/api-stage/shared/storage/app storage/app &&
|
|
|
|
|
composer install --no-dev --optimize-autoloader --no-interaction &&
|
|
|
|
|
php artisan config:cache &&
|
|
|
|
|
php artisan route:cache &&
|
|
|
|
|
php artisan view:cache &&
|
|
|
|
|
php artisan migrate --force &&
|
|
|
|
|
ln -sfn /home/webservice/api-stage/releases/${RELEASE_ID} /home/webservice/api-stage/current &&
|
|
|
|
|
sudo systemctl reload php8.4-fpm &&
|
|
|
|
|
cd /home/webservice/api-stage/releases && ls -1dt */ | tail -n +4 | xargs rm -rf 2>/dev/null || true
|
|
|
|
|
'
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 10:44:54 +09:00
|
|
|
// ── 운영 배포 승인 (런칭 후 활성화) ──
|
|
|
|
|
// stage('Production Approval') {
|
|
|
|
|
// when { branch 'main' }
|
|
|
|
|
// steps {
|
|
|
|
|
// slackSend channel: '#product_deploy', color: '#FF9800', tokenCredentialId: 'slack-token',
|
|
|
|
|
// message: "🔔 *api* 운영 배포 승인 대기 중\n${env.GIT_COMMIT_MSG}\nStage API: https://stage-api.sam.it.kr\n<${env.BUILD_URL}input|승인하러 가기>"
|
|
|
|
|
// timeout(time: 24, unit: 'HOURS') {
|
|
|
|
|
// input message: 'Stage 확인 후 운영 배포를 진행하시겠습니까?\nStage API: https://stage-api.sam.it.kr',
|
|
|
|
|
// ok: '운영 배포 진행'
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2026-02-24 13:22:22 +09:00
|
|
|
|
2026-02-24 08:15:05 +09:00
|
|
|
// ── main → 운영서버 Production 배포 ──
|
|
|
|
|
stage('Deploy Production') {
|
|
|
|
|
when { branch 'main' }
|
|
|
|
|
steps {
|
|
|
|
|
sshagent(credentials: ['deploy-ssh-key']) {
|
|
|
|
|
sh """
|
2026-02-24 13:22:22 +09:00
|
|
|
ssh ${DEPLOY_USER}@211.117.60.189 'mkdir -p /home/webservice/api/releases/${RELEASE_ID}'
|
2026-02-24 08:15:05 +09:00
|
|
|
rsync -az --delete \
|
2026-02-24 17:41:22 +09:00
|
|
|
--exclude='.git' --exclude='.env' \
|
|
|
|
|
--exclude='storage/app' --exclude='storage/logs' \
|
|
|
|
|
--exclude='storage/framework/sessions' --exclude='storage/framework/cache' \
|
2026-02-24 08:15:05 +09:00
|
|
|
. ${DEPLOY_USER}@211.117.60.189:/home/webservice/api/releases/${RELEASE_ID}/
|
|
|
|
|
ssh ${DEPLOY_USER}@211.117.60.189 '
|
|
|
|
|
cd /home/webservice/api/releases/${RELEASE_ID} &&
|
2026-02-24 23:00:32 +09:00
|
|
|
mkdir -p bootstrap/cache storage/framework/{views,cache/data,sessions} storage/logs &&
|
2026-02-27 10:44:54 +09:00
|
|
|
sudo chown -R www-data:webservice storage bootstrap/cache &&
|
|
|
|
|
sudo chmod -R 775 storage bootstrap/cache &&
|
2026-02-24 08:15:05 +09:00
|
|
|
ln -sfn /home/webservice/api/shared/.env .env &&
|
2026-03-03 09:51:07 +09:00
|
|
|
sudo chmod 640 /home/webservice/api/shared/.env &&
|
2026-02-24 08:15:05 +09:00
|
|
|
ln -sfn /home/webservice/api/shared/storage/app storage/app &&
|
|
|
|
|
composer install --no-dev --optimize-autoloader --no-interaction &&
|
|
|
|
|
php artisan config:cache &&
|
|
|
|
|
php artisan route:cache &&
|
|
|
|
|
php artisan view:cache &&
|
|
|
|
|
php artisan migrate --force &&
|
|
|
|
|
ln -sfn /home/webservice/api/releases/${RELEASE_ID} /home/webservice/api/current &&
|
|
|
|
|
sudo systemctl reload php8.4-fpm &&
|
|
|
|
|
sudo supervisorctl restart sam-queue-worker:* &&
|
|
|
|
|
cd /home/webservice/api/releases && ls -1dt */ | tail -n +6 | xargs rm -rf 2>/dev/null || true
|
|
|
|
|
'
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// develop → Jenkins 관여 안함 (기존 post-update hook 유지)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
post {
|
2026-02-24 20:45:50 +09:00
|
|
|
success {
|
2026-03-05 11:32:16 +09:00
|
|
|
slackSend channel: '#deploy_api', color: 'good', tokenCredentialId: 'slack-token',
|
2026-02-25 12:52:17 +09:00
|
|
|
message: "✅ *api* 배포 성공 (`${env.BRANCH_NAME}`)\n${env.GIT_COMMIT_MSG}\n<${env.BUILD_URL}|빌드 #${env.BUILD_NUMBER}>"
|
2026-02-24 20:45:50 +09:00
|
|
|
}
|
2026-02-24 08:15:05 +09:00
|
|
|
failure {
|
2026-03-05 11:32:16 +09:00
|
|
|
slackSend channel: '#deploy_api', color: 'danger', tokenCredentialId: 'slack-token',
|
2026-02-25 12:52:17 +09:00
|
|
|
message: "❌ *api* 배포 실패 (`${env.BRANCH_NAME}`)\n${env.GIT_COMMIT_MSG}\n<${env.BUILD_URL}|빌드 #${env.BUILD_NUMBER}>"
|
2026-02-24 08:15:05 +09:00
|
|
|
script {
|
2026-02-24 13:22:22 +09:00
|
|
|
if (env.BRANCH_NAME == 'main') {
|
2026-02-24 08:15:05 +09:00
|
|
|
sshagent(credentials: ['deploy-ssh-key']) {
|
|
|
|
|
sh """
|
|
|
|
|
ssh ${DEPLOY_USER}@211.117.60.189 '
|
2026-02-24 13:22:22 +09:00
|
|
|
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 &&
|
2026-02-24 08:15:05 +09:00
|
|
|
sudo systemctl reload php8.4-fpm
|
2026-02-24 13:22:22 +09:00
|
|
|
' || true
|
2026-02-24 08:15:05 +09:00
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-24 17:41:22 +09:00
|
|
|
}
|