forked from cadetbluee/project-pushoflife
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
81 lines (67 loc) · 2.22 KB
/
Jenkinsfile
File metadata and controls
81 lines (67 loc) · 2.22 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
pipeline {
agent any
stages {
stage('Build Backend') {
steps {
script {
dir('BackEnd/PushOfLife') {
// Gradle 빌드
sh 'chmod +x gradlew'
sh './gradlew build'
}
dir('BackEnd/notification') {
// Gradle 빌드
sh 'chmod +x gradlew'
sh './gradlew build'
}
}
}
}
stage('Build Backend Images') {
steps {
echo 'Building Backend Docker Images...'
script {
// Build main server Docker image
dir('BackEnd/PushOfLife') {
sh 'docker build -t pol/spring .'
}
// Build notification server Docker image
dir('BackEnd/notification') {
sh 'docker build -t pol/notify .'
}
}
}
}
stage('Cleanup Old Images') {
steps {
script {
sh '''
# Remove dangling images
docker image prune -f
# Remove images that start with 'alleat/' and do not have the 'latest' tag
docker images --filter "dangling=false" --format "{{.Repository}}:{{.Tag}}" | grep '^alleat/' | grep -v ':latest' | while read -r image; do
docker rmi -f "$image" || true
done
'''
}
}
}
stage('Deploy using Docker Down') {
steps{
echo 'Docker Compose... Down'
sh 'docker-compose -f /home/docker-compose.yml down'
}
}
stage('Deploy using Docker Compose') {
steps{
echo 'Deploying using Docker Compose...'
sh 'docker-compose -f /home/docker-compose.yml up -d'
}
}
}
post {
always {
cleanWs()
}
}
}