SPMS_WEB/Jenkinsfile
SEAN bb82846d59
Some checks failed
SPMS_BO/pipeline/head There was a failure building this commit
fix: Jenkinsfile 프론트 빌드 소스 복사 방식 수정
정지된 컨테이너에 docker cp하면 바인드 마운트에 반영되지 않아
호스트 볼륨의 옛날 소스로 빌드되는 문제 해결.
임시 alpine 컨테이너를 통해 호스트 볼륨에 직접 복사하도록 변경.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 16:22:48 +09:00

83 lines
2.9 KiB
Groovy

def TARGET_FRONT_BUILD = ''
def TARGET_RUN_SERVER = ''
def FRONT_HOST_PATH = '/volume1/SPMS/PROJECT/Application/Front'
pipeline {
agent any
stages {
stage('Check Branch & Setup') {
steps {
script {
def branchName = env.BRANCH_NAME
echo "Current Branch: ${branchName}"
if (branchName == 'develop') {
TARGET_FRONT_BUILD = 'spms-front-build-debug'
TARGET_RUN_SERVER = 'spms-run-debug'
echo "[DEV Mode] Target: DEBUG Container"
}
else if (branchName == 'main') {
TARGET_FRONT_BUILD = 'spms-front-build-release'
TARGET_RUN_SERVER = 'spms-run-release'
echo ">>> [PROD Mode] Target: RELEASE Container"
}
else {
error "This branch(${branchName}) can't set container (USE develop or main branch)"
}
}
}
}
stage('Checkout') {
steps {
cleanWs()
checkout scm
echo "Git Checkout Complete"
}
}
// [3단계] 실행 중인 임시 컨테이너를 통해 호스트 볼륨에 소스 복사
// (정지된 컨테이너에 docker cp하면 바인드 마운트에 반영 안 됨)
stage('Copy to Host Volume') {
steps {
script {
def sourcePath = "${WORKSPACE}/react/."
echo "Copying source to host volume (${FRONT_HOST_PATH})..."
sh """
docker rm -f spms-source-copy 2>/dev/null || true
docker run -d --name spms-source-copy \
-v ${FRONT_HOST_PATH}:/target \
alpine sleep 30
docker exec spms-source-copy sh -c \
'find /target -mindepth 1 -maxdepth 1 ! -name node_modules -exec rm -rf {} +'
docker cp ${sourcePath} spms-source-copy:/target/
docker rm -f spms-source-copy
"""
echo "Source copy complete."
}
}
}
stage('Build Frontend') {
steps {
script {
echo "Starting React Build (npm install + build + deploy)..."
sh "docker start -a ${TARGET_FRONT_BUILD}"
echo "React Build Complete."
}
}
}
stage('Apply & Restart') {
steps {
script {
echo "Restarting Backend Server (${TARGET_RUN_SERVER})..."
sh "docker restart ${TARGET_RUN_SERVER}"
}
}
}
}
}