-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjenkinsfile
More file actions
104 lines (90 loc) · 3.31 KB
/
jenkinsfile
File metadata and controls
104 lines (90 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
pipeline {
agent any
environment {
GITHUB_REPO = 'https://github.com/nova-mk3/frontend'
GITHUB_CREDENTIALS_ID = 'frontend_github_token' // GitHub 자격 증명 ID
}
stages {
stage('GitHub Clone') {
steps {
script {
echo "🔄 Cloning repository..."
sh 'rm -rf frontend || true' // 기존 폴더 삭제
checkout([
$class: 'GitSCM',
branches: [[name: '*/main']],
userRemoteConfigs: [[
url: env.GITHUB_REPO,
credentialsId: env.GITHUB_CREDENTIALS_ID
]],
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'frontend']]
])
echo "✅ Git Clone 완료!"
}
}
}
stage('Inject .env.production') {
steps {
withCredentials([file(credentialsId: 'frontend_env_files', variable: 'ENV_FILE')]) {
script {
// frontend/apps/service로 복사
dir('frontend/apps/service') {
sh "cp $ENV_FILE .env.production"
echo "✅ service .env.production 복사 완료"
}
// frontend/apps/admin으로 복사
dir('frontend/apps/admin') {
sh "cp $ENV_FILE .env.production"
echo "✅ admin .env.production 복사 완료"
}
}
}
}
}
stage('Cleanup') {
steps {
script {
def composeFile = "frontend/docker-compose.yml"
if (fileExists(composeFile)) {
echo "🧹 Cleaning up old Docker containers..."
dir('frontend') {
sh '''
docker compose down --rmi all --volumes --remove-orphans || true
docker rmi frontend_admin_image:latest frontend_service_image:latest || true
'''
}
echo "✅ Cleanup 완료!"
} else {
echo "⚠️ frontend/docker-compose.yml not found. Skipping cleanup."
}
}
}
}
stage('Deploy') {
steps {
script {
def composeFile = "frontend/docker-compose.yml"
if (fileExists(composeFile)) {
echo "🚀 Deploying Docker containers..."
dir('frontend') {
sh '''
docker compose up -d --build || (echo "❌ Deployment Failed!" && exit 1)
'''
}
echo "✅ Deployment 완료!"
} else {
error "❌ docker-compose.yml not found! Stopping pipeline."
}
}
}
}
}
post {
success {
echo "🎉 Deployment 성공! 🚀"
}
failure {
echo "❌ Deployment 실패. Logs 확인 요망."
}
}
}