-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
146 lines (129 loc) ยท 5.19 KB
/
Copy pathJenkinsfile
File metadata and controls
146 lines (129 loc) ยท 5.19 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
pipeline {
agent any
parameters {
choice(
name: 'PROFILE',
choices: [
'test-real-data,prod,batch,es',
'prod,batch',
'dev',
'test-real-data',
'prod',
'batch',
'es',
'test-real-data,prod,batch,es',
'dev,batch,es'
]
)
}
tools {
jdk 'openjdk-21-jdk'
}
environment {
COMPOSE_FILE = 'docker-compose.yml'
SPRING_PROFILES_ACTIVE = "${params.PROFILE}"
// BuildKit for faster Docker builds
DOCKER_BUILDKIT = '1'
BUILDKIT_PROGRESS = 'plain'
}
stages {
stage('Prepare') {
steps {
git branch: 'main',
url: 'https://github.com/ShootPointer/ShootPointer_BE.git'
}
post {
success { sh 'echo "โ
Successfully Cloned Repository"' }
failure { sh 'echo "โ Failed to Clone Repository"' }
}
}
stage('Replace Properties') {
steps {
script {
withCredentials([
file(credentialsId: 'SECRET_FILE2', variable: 'secretFile'),
file(credentialsId: 'SECRET_DOCKER_ENV', variable: 'envFile')
]) {
sh '''
echo "๐ Replacing application.yml and .env files..."
cp $secretFile ./src/main/resources/application.yml
cp $envFile .env
echo "โ
Secret files replaced successfully."
'''
}
}
}
}
stage('Preparation') {
parallel {
stage('Clean Up Used Ports & Containers') {
steps {
sh '''
echo "๐งน Cleaning up all non-Jenkins containers and freeing ports..."
# Jenkins ์ปจํ
์ด๋ ์ ์ธํ๊ณ ๋ชจ๋ ์ค์ง ๋ฐ ์ญ์
JENKINS_CONTAINER=$(docker ps -aqf "name=jenkins")
ALL_CONTAINERS=$(docker ps -aq)
for CONTAINER in $ALL_CONTAINERS; do
if [ "$CONTAINER" != "$JENKINS_CONTAINER" ]; then
echo "Stopping and removing container: $CONTAINER"
docker stop $CONTAINER || true
docker rm -f $CONTAINER || true
fi
done
# ๋ก์ปฌ MongoDB ๋ฐ๋ชฌ์ด ์ผ์ ธ ์์ผ๋ฉด ์ค๋จ
if pgrep mongod > /dev/null; then
echo "Stopping local MongoDB daemon..."
sudo systemctl stop mongod || true
fi
# ํฌํธ ์ถฉ๋ ๋ฐฉ์ง์ฉ ์ฃผ์ ํฌํธ ํด์
for port in 5432 5431 27017 27016 9200 6379 5601; do
PID=$(lsof -ti :$port || true)
if [ ! -z "$PID" ]; then
echo "Killing process on port $port (PID: $PID)"
sudo kill -9 $PID || true
fi
done
# docker-compose ์์ฌ ์ปจํ
์ด๋ ์ ๋ฆฌ
docker-compose down --remove-orphans || true
echo "โ
Port and container cleanup complete."
'''
}
post {
success { sh 'echo "โ
Cleanup completed successfully."' }
failure { sh 'echo "โ Cleanup failed."' }
}
}
}
}
stage('Fix Elasticsearch Volume Permissions') {
steps {
sh '''
echo "๐ง Fixing Elasticsearch volume permissions..."
mkdir -p esdata es-logs
chown -R 1000:1000 esdata es-logs || true
chmod -R 775 esdata es-logs
echo "โ
Elasticsearch data/log volume permissions fixed."
'''
}
post {
success { sh 'echo "โ
Volume permissions fixed successfully."' }
failure { sh 'echo "โ Failed to fix volume permissions."' }
}
}
stage('Build and Deploy with Docker Compose') {
steps {
sh '''
echo "๐ Starting deployment with profiles: $SPRING_PROFILES_ACTIVE"
SPRING_PROFILES_ACTIVE=$SPRING_PROFILES_ACTIVE docker-compose up -d --build
'''
}
environment {
JAVA_TOOL_OPTIONS = "-Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=86400"
}
post {
success { sh 'echo "โ
Successfully Deployed with Docker Compose"' }
failure { sh 'echo "โ Failed to Deploy with Docker Compose"' }
}
}
}
}