-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
125 lines (104 loc) · 4.28 KB
/
Jenkinsfile
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
pipeline {
agent any
stages {
stage('Build Backend') {
steps {
script {
dir('backend/Arbaguette') {
sh 'chmod +x ./gradlew'
sh './gradlew clean build -x test'
sh """
sed -i 's/\${AWS_ACCESS_KEY}/${AWS_ACCESS_KEY}/' ./src/main/resources/application.properties
sed -i 's/\${AWS_SECRET_KEY}/${AWS_SECRET_KEY}/' ./src/main/resources/application.properties
sed -i 's/\${DB_NAME}/${DB_NAME}/' ./src/main/resources/application.properties
sed -i 's/\${DB_PASSWORD}/${DB_PASSWORD}/' ./src/main/resources/application.properties
sed -i 's/\${SSAFY_BANK_KEY}/${SSAFY_BANK_KEY}/' ./src/main/resources/application.properties
"""
// Check if any container is named "backend"
def containerNamedBackend = sh(script: "docker ps -a --filter 'name=backend' --format '{{.ID}}'", returnStdout: true).trim()
if (containerNamedBackend) {
// Stop and remove the container named "backend"
sh "docker stop ${containerNamedBackend}"
sh "docker rm ${containerNamedBackend}"
}
// Build and run the new backend container
sh """
docker build \
--build-arg AWS_ACCESS_KEY=${AWS_ACCESS_KEY} \
--build-arg AWS_SECRET_KEY=${AWS_SECRET_KEY} \
--build-arg DB_NAME=${DB_NAME} \
--build-arg DB_PASSWORD=${DB_PASSWORD} \
--build-arg SSAFY_BANK_KEY=${SSAFY_BANK_KEY} \
-t backend .
"""
sh """
docker run --name backend -d -p 8080:8080 \
-v /home/ubuntu/api_key/cloudvision-434807-1bea29b95286.json:/app/config/cloudvision.json \
-e GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS} \
-e AWS_ACCESS_KEY=${AWS_ACCESS_KEY} \
-e AWS_SECRET_KEY=${AWS_SECRET_KEY} \
-e DB_NAME=${DB_NAME} \
-e DB_PASSWORD=${DB_PASSWORD} \
-e SSAFY_BANK_KEY=${SSAFY_BANK_KEY} \
-e TZ=Asiz/Seoul \
backend
"""
}
dir('backend/bonus') {
sh 'chmod +x ./gradlew'
sh './gradlew clean build -x test'
sh """
sed -i 's/\${DB_NAME}/${MARIA_NAME}/' ./src/main/resources/application.properties
sed -i 's/\${DB_PASSWORD}/${MARIA_PASSWORD}/' ./src/main/resources/application.properties
sed -i 's/\${SSAFY_BANK_KEY}/${SSAFY_BANK_KEY}/' ./src/main/resources/application.properties
"""
// Check if any container is named "backend"
def containerNamedBackend = sh(script: "docker ps -a --filter 'name=bonus' --format '{{.ID}}'", returnStdout: true).trim()
if (containerNamedBackend) {
// Stop and remove the container named "bonus"
sh "docker stop ${containerNamedBackend}"
sh "docker rm ${containerNamedBackend}"
}
// Build and run the new backend container
sh """
docker build \
--build-arg DB_NAME=${MARIA_NAME} \
--build-arg DB_PASSWORD=${MARIA_PASSWORD} \
--build-arg SSAFY_BANK_KEY=${SSAFY_BANK_KEY} \
-t bonus .
"""
sh """
docker run --name bonus -d -p 8088:8088 \
-e DB_NAME=${MARIA_NAME} \
-e DB_PASSWORD=${MARIA_PASSWORD} \
-e SSAFY_BANK_KEY=${SSAFY_BANK_KEY} \
-e TZ=Asiz/Seoul \
bonus
"""
}
}
}
}
}
post {
success {
script {
// 빌드를 실행한 사용자 정보 가져오기
def user = sh(script: 'git log -1 --pretty=format:"%an"', returnStdout: true).trim()
mattermostSend (color: 'good',
message: "배포 성공. ${user}",
)
}
}
failure {
script {
// 빌드를 실행한 사용자 정보 가져오기
// Git 정보를 통해 푸시한 사용자 확인
def user = sh(script: 'git log -1 --pretty=format:"%an"', returnStdout: true).trim()
mattermostSend (color: 'danger',
message: "배포 실패. 범인 : ${user}",
)
}
}
}
}