-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
161 lines (152 loc) · 7.17 KB
/
Jenkinsfile
File metadata and controls
161 lines (152 loc) · 7.17 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
pipeline {
agent any
environment {
BACKEND_IMAGE = "hyokii/s14d109"
FRONTEND_IMAGE = "hyokii/s14d109-frontend"
AI_IMAGE = "hyokii/s14d109-ai"
STT_IMAGE = "hyokii/s14d109-stt"
REMOTE_IP = "${env.REMOTE_IP}"
MM_HOOK = "https://meeting.ssafy.com/hooks/s9t97bkc8pgmbpyjwjbxx37hhh"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build and Push Images') {
parallel {
// 1. 백엔드 빌드 및 푸시
stage('[Backend] Docker Build & Push') {
when { changeset "backend/**" }
steps {
dir('backend') {
sh "docker build -t ${BACKEND_IMAGE}:latest ."
withCredentials([usernamePassword(credentialsId: 'docker-hub-id', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh "echo \$DOCKER_PASS | docker login -u \$DOCKER_USER --password-stdin"
sh "docker push ${BACKEND_IMAGE}:latest"
}
}
}
post {
failure {
mattermostSend(color: 'danger', message: "❌ [Backend] 도커 빌드 및 푸시 실패!", endpoint: "${MM_HOOK}", channel: 'C2S')
}
}
}
// 2. 프론트엔드 빌드 및 푸시
stage('[Frontend] Docker Build & Push') {
when { changeset "frontend/**" }
steps {
script {
withCredentials([
string(credentialsId: 'VITE_API_BASE_URL', variable: 'API_URL'),
string(credentialsId: 'VITE_WS_URL', variable: 'WS_URL'),
string(credentialsId: 'VITE_LIVEKIT_URL', variable: 'OV_URL'),
string(credentialsId: 'VITE_STT_BASE', variable: 'STT_URL')
]) {
dir('frontend') {
sh """
docker build --no-cache \
--build-arg VITE_API_BASE_URL='${API_URL}' \
--build-arg VITE_WS_URL='${WS_URL}' \
--build-arg VITE_LIVEKIT_URL='${OV_URL}'\
--build-arg VITE_STT_BASE='${STT_URL}' \
-t ${FRONTEND_IMAGE}:latest .
"""
withCredentials([usernamePassword(credentialsId: 'docker-hub-id', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh "echo \$DOCKER_PASS | docker login -u \$DOCKER_USER --password-stdin"
sh "docker push ${FRONTEND_IMAGE}:latest"
}
}
}
}
}
post {
failure {
mattermostSend(color: 'danger', message: "❌ [Frontend] 도커 빌드 및 푸시 실패!", endpoint: "${MM_HOOK}", channel: 'C2S')
}
}
}
// 3. RAG 서버 빌드 및 푸시
stage('[AI-RAG] Docker Build & Push') {
when { changeset "ai/rag_server/**" }
steps {
dir('ai/rag_server') {
script {
sh "docker build -t ${AI_IMAGE}:latest ."
withCredentials([usernamePassword(credentialsId: 'docker-hub-id', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh "echo \$DOCKER_PASS | docker login -u \$DOCKER_USER --password-stdin"
sh "docker push ${AI_IMAGE}:latest"
}
}
}
}
post {
failure {
mattermostSend(color: 'danger', message: "❌ [AI-RAG] 도커 빌드 및 푸시 실패!", endpoint: "${MM_HOOK}", channel: 'C2S')
}
}
}
// 3. STT 서버 빌드 및 푸시
stage('[AI-STT] Docker Build & Push') {
when { changeset "ai/stt_server/**" }
steps {
dir('ai/stt_server') {
script {
sh "docker build -t ${STT_IMAGE}:latest ."
withCredentials([usernamePassword(credentialsId: 'docker-hub-id', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh "echo \$DOCKER_PASS | docker login -u \$DOCKER_USER --password-stdin"
sh "docker push ${STT_IMAGE}:latest"
}
}
}
}
post {
failure {
mattermostSend(color: 'danger', message: "❌ [AI-STT] 도커 빌드 및 푸시 실패!", endpoint: "${MM_HOOK}", channel: 'C2S')
}
}
}
}
}
stage('Deploy') {
steps {
sshagent(['ssafy-server-key']) {
echo "운영 서버에 접속하여 배포를 시작합니다."
sh """
ssh -o StrictHostKeyChecking=no ubuntu@${env.REMOTE_IP} '
cd /home/ubuntu/project && \
sudo docker compose pull && \
sudo docker compose up -d
'
"""
}
}
}
}
post {
success {
script {
def author = sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
def commitMsg = sh(script: "git show -s --pretty=%B", returnStdout: true).trim()
def branch = env.BRANCH_NAME ?: "dev"
mattermostSend(
color: 'good',
message: """
✅ **전체 서비스 배포 성공 (Build #${env.BUILD_NUMBER})**
- **담당자**: ${author}
- **브랜치**: `${branch}`
- **커밋 내용**: ${commitMsg}
- **접속 주소**: https://i14d109.p.ssafy.io
""".stripIndent(),
endpoint: "${MM_HOOK}",
channel: 'C2S'
)
}
}
failure {
mattermostSend(color: 'danger', message: "🚨 배포 파이프라인 전체 실패 (Build #${env.BUILD_NUMBER})", endpoint: "${MM_HOOK}", channel: 'C2S')
}
}
}