-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsFile
More file actions
94 lines (79 loc) · 2.44 KB
/
JenkinsFile
File metadata and controls
94 lines (79 loc) · 2.44 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
pipeline {
agent any
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10', daysToKeepStr: '30'))
timeout(time: 30, unit: 'MINUTES')
timestamps()
}
environment {
IMAGE_NAME = '2thecore-emulator'
DOCKER_REPO = 'yeonjin529/2thecore-emulator'
DEPLOY_HOST = '3.37.93.107'
APP_PORT = '8081'
}
stages {
stage('Build Emulator JAR') {
steps {
sh '''
set -e
chmod +x ./gradlew
./gradlew --no-daemon clean bootJar -x test
'''
}
}
stage('Assemble deploy bundle') {
steps {
withCredentials([file(credentialsId: '2thecore-env', variable: 'PROD_ENV')]) {
sh '''
set -e
rm -rf deploy
mkdir -p deploy/release/emulator
# 빌드 결과물 복사
cp build/libs/emulator-0.0.1-SNAPSHOT.jar deploy/release/emulator/app.jar
# Dockerfile 복사
cp Dockerfile deploy/Dockerfile.emulator
# Jenkins Credentials -> prod.env 파일로 추가
cp $PROD_ENV deploy/release/emulator/prod.env
# tar 압축
tar -czf emulator-bundle.tar -C deploy .
echo "[OK] emulator-bundle.tar 생성 (app.jar + prod.env 포함)"
'''
}
}
}
stage('Deploy to EC2') {
steps {
sshagent(['2thecore-ec2']) {
sh '''
set -e
# 번들 전송
scp -o StrictHostKeyChecking=no emulator-bundle.tar ubuntu@${DEPLOY_HOST}:~
# EC2에서 배포 실행
ssh -o StrictHostKeyChecking=no ubuntu@${DEPLOY_HOST} bash -lc "
set -e
rm -rf ~/emulator-deploy && mkdir -p ~/emulator-deploy
tar -xzf ~/emulator-bundle.tar -C ~/emulator-deploy
cd ~/emulator-deploy
# 기존 컨테이너 제거
docker rm -f ${IMAGE_NAME} || true
# 새 이미지 빌드 및 실행 (prod.env 포함됨)
docker build -t ${DOCKER_REPO}:dev -f Dockerfile.emulator .
docker run -d --name ${IMAGE_NAME} \\
-p ${APP_PORT}:${APP_PORT} \\
--restart unless-stopped \\
${DOCKER_REPO}:dev
# tar 삭제
rm -f ~/emulator-bundle.tar || true
"
'''
}
}
}
}
post {
always {
echo "Pipeline finished."
}
}
}