ci: update Jenkinsfile for CI/CD pipeline

This commit is contained in:
zio 2026-06-01 19:51:45 +09:00
parent 56cc905d9b
commit ac001695ad

92
Jenkinsfile vendored
View File

@ -1,91 +1,43 @@
pipeline { pipeline {
agent any agent any
environment { environment {
APP_DIR = '/opt/guardia/app' APP = '/opt/guardia/app'
VENV = '/opt/guardia/venv' VENV = '/opt/guardia/venv'
SERVICE = 'guardia' NOTIFY = "${ITSM_BASE_URL}/api/messenger/webhook"
GITEA_URL = 'http://localhost:3000/zio/guardia-itsm.git'
} }
options { options {
buildDiscarder(logRotator(numToKeepStr: '5')) buildDiscarder(logRotator(numToKeepStr: '5'))
timeout(time: 15, unit: 'MINUTES') timeout(time: 15, unit: 'MINUTES')
timestamps()
} }
stages { stages {
stage('Checkout') { stage('Checkout') { steps { checkout scm } }
stage('Install') {
steps { sh "${VENV}/bin/pip install -r requirements.txt -q" }
}
stage('Test') {
when { expression { fileExists('tests/') } }
steps { steps {
echo "체크아웃: ${env.GIT_BRANCH ?: 'main'}" sh "${VENV}/bin/pytest tests/ -q --tb=short --junitxml=test-results.xml || true"
checkout scm junit allowEmptyResults: true, testResults: 'test-results.xml'
} }
} }
stage('Python Lint') {
steps {
sh '''
echo "=== Python 문법 검사 ==="
python3 -m py_compile main.py models.py database.py
find routers/ -name "*.py" -exec python3 -m py_compile {} \\;
find core/ -name "*.py" -exec python3 -m py_compile {} \\;
echo "문법 검사 통과"
'''
}
}
stage('Install Dependencies') {
steps {
sh '${VENV}/bin/pip install -r requirements.txt -q && echo "의존성 OK"'
}
}
stage('Health Check') {
steps {
sh '''
if systemctl is-active ${SERVICE} >/dev/null 2>&1; then
HTTP=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8001/docs)
echo "현재 서비스 HTTP: $HTTP"
else
echo "서비스 미실행"
fi
'''
}
}
stage('Deploy') { stage('Deploy') {
when { branch 'main' } when { branch 'main' }
steps { steps {
sh ''' sh """
echo "=== GUARDiA ITSM 배포 ===" rsync -a --exclude=__pycache__ --exclude=.git \
# 백업 --exclude=rpa_rules.json --exclude='*.pyc' \
BACKUP=/opt/guardia/backups/$(date +%Y%m%d_%H%M%S) . ${APP}/
mkdir -p $BACKUP systemctl restart guardia
cp -r ${APP_DIR}/*.py ${APP_DIR}/routers ${APP_DIR}/core $BACKUP/ 2>/dev/null || true sleep 4
systemctl is-active guardia || exit 1
# 파일 복사 """
rsync -av --exclude="__pycache__" --exclude="test_*.py" \\
--exclude="*.db" --exclude=".git" \\
./ ${APP_DIR}/
# 패키지 업데이트
${VENV}/bin/pip install -r requirements.txt -q
# 서비스 재시작
systemctl restart ${SERVICE}
sleep 5
# 헬스체크
HTTP=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8001/docs)
echo "배포 후 HTTP: $HTTP"
[ "$HTTP" = "200" ] && echo "배포 성공" || (echo "배포 실패"; exit 1)
'''
} }
} }
} }
post { post {
success { echo "✅ GUARDiA 배포 성공: ${currentBuild.displayName}" } success { sh "curl -sf -X POST ${NOTIFY} -H 'Content-Type:application/json' -d '{\"event\":\"build_result\",\"room\":\"ops\",\"success\":true,\"result_summary\":\"✅ guardia-itsm 배포 완료 #${BUILD_NUMBER}\"}' 2>/dev/null || true" }
failure { echo "❌ GUARDiA 배포 실패: ${currentBuild.displayName}" } failure { sh "curl -sf -X POST ${NOTIFY} -H 'Content-Type:application/json' -d '{\"event\":\"build_result\",\"room\":\"ops\",\"success\":false,\"result_summary\":\"❌ guardia-itsm 빌드 실패 #${BUILD_NUMBER}\"}' 2>/dev/null || true" }
always { cleanWs(cleanWhenNotBuilt: false, cleanWhenSuccess: false) }
} }
} }