-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-Backend
200 lines (171 loc) · 6.86 KB
/
Jenkinsfile-Backend
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
pipeline {
options {
skipDefaultCheckout()
timeout(time: 1, unit: 'HOURS')
} // options
environment {
registry = 'othom'
repo = 'e-commerce-backend-blue'
DOCKERHUB_CREDENTIALS = credentials('DOCKER_AUTH_ID')
DOCKERHUB_REPO = "${registry}/${repo}"
TAG = "${BUILD_NUMBER}" // 'latest'
} // environment
agent none
stages {
stage('Setup') {
agent any
steps {
// Login To Docker
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
// Clear all things Docker
sh 'docker system prune -af --volumes'
// Check The ENV Is Clean
sh 'docker-compose ps -a'
sh 'docker ps -a'
}
}
stage('Build') {
agent { label 'build-agent' }
steps {
dir('backend') {
echo '\n\nBUILDING... \n'
// sh "docker build -t ${DOCKERHUB_REPO} ." //:${TAG}
// echo '\n\nStarting Backend... \n'
// sh "docker run -d -p 5000:5000 --rm --name ${repo}-container ${DOCKERHUB_REPO}"
// echo "Please Visit --> $BACKEND_URL:5000/api/product"
}
}
}
stage('Test') {
agent { label 'build-agent' }
steps {
dir('backend') {
echo '\n\nTESTING... \n'
echo '\n\n SKIPPING TESTING... \n'
}
}
}
stage('Push') {
agent { label 'deploy-agent' }
steps {
echo '\n\nPUSHING... \n'
sh "docker push ${DOCKERHUB_REPO}" //:${TAG}
}
}
stage('Smoke Test') {
options {
timeout(time: 2, unit "MINUTES")
}
steps {
input(message: "Run Live Tests?", ok; "Yes")
}
}
// stage("Run Smoke Tests Against The Container") {
// agent { label 'deploy-agent' }
// steps {
// dir('backend') {
// sh 'docker kill $(docker ps -q)'
// echo '\n\nRE-BUILD LATEST FROM DOCKER HUB... \n'
// sh "docker build -t ${DOCKERHUB_REPO} ." //:${TAG}
// echo "\n\nStarting Web Server FOR SMOKE TESTS... \n"
// sh "docker run -d -p 5000:5000 --rm --name ${repo}-container ${DOCKERHUB_REPO}"
// echo "\nPlease Visit --> $BASE_URL:5000"
// sh "curl ${BASE_URL}:5000 | jq"
// }
// }
// }
stage('Pull') {
agent { label 'deploy-agent' }
steps {
echo '\n\nPULLING... \n'
sh "docker pull ${DOCKERHUB_REPO}" //:${TAG}
}
}
stage('Accept Deployments') {
options { timeout(time: 2, unit "MINUTES") }
steps {
input(message: "Approve Deploy?", ok; "Yes")
}
}
stage('Deploy') {
agent { label 'deploy-agent' }
steps {
dir('backend') {
echo '\n\nDEPLOYING... \n'
container('kubectl') {
sh 'kubectl apply -f Backend-Service.yaml'
sh 'kubectl apply -f Backend-Deployment-Blue.yaml'
}
container('docker') {
sh 'docker run --rm --name kubectl bitnami/kubectl:latest get pod'
}
}
}
}
// stage('Deploy To Staging') {
// options { timeout(time: 2, unit "MINUTES") }
// steps {
// dir('backend') {
// echo 'Used To Configure Both Blue & Green Deployments'
// // sh ''
// sh 'minikube start' // Change to EKS
// sh 'kubectl network PROD'
// sh 'kubectl apply -f flask-app-deployment.yml' // PROD Deployment
// sh 'kubectl apply -f flask-app-service.yml'
// // sh 'docker push chamoo334/p2official:Prod'
// }
// }
// }
// stage('Deploy To Blue Production') {
// options { timeout(time: 2, unit "MINUTES") }
// steps {
// dir('backend') {
// echo 'Only Allow Deployments Tagged As A Blue-Feature'
// // sh ''
// sh 'minikube start' // Change to EKS
// sh 'kubectl network BLUE'
// sh 'kubectl apply -f flask-app-deployment.yml' // BLUE Deployment
// sh 'kubectl apply -f flask-app-service.yml'
// // sh 'docker push chamoo334/p2official:Blue'
// }
// }
// }
// stage('Deploy To Green Production') {
// options { timeout(time: 2, unit "MINUTES") }
// steps {
// dir('backend') {
// echo 'Only Allow Deployments Tagged As A Green-Feature'
// // sh ''
// sh 'minikube start' // Change to EKS
// sh 'kubectl network GREEN'
// sh 'kubectl apply -f flask-app-deployment.yml' // GREEN Deployment
// sh 'kubectl apply -f flask-app-service.yml'
// // sh 'docker push chamoo334/p2official:Green'
// }
// }
// }
}
post {
always {
// Clean Everything UP -- Docker
// sh 'docker-compose down --remove-orphans -v'
// sh 'docker kill $(docker ps -q)'
// Clean The Docker ENV
// sh 'docker rm $(docker ps -a -q)'
// sh 'docker rmi $(docker images -q)'
// sh 'docker rmi $(path_current_build)'
sh 'docker system prune -af && docker logout'
// Send Status Report To Email & Discord
mail to: '[email protected]',
subject: "Job '${JOB_NAME}' (${BUILD_NUMBER}) Was A ${currentBuild.currentResult}",
body: "Please go to ${BUILD_URL} and verify the build"
discordSend webhookURL: 'https://discord.com/api/webhooks/998320738769588224/4akFNyQItbFvUKmbGxJ-qMCyzMefF3QP4GbyNk73wry4_WfGPuDOWUlael_WN4_Yh677',
enableArtifactsList: false, scmWebUrl: '',
image: '', thumbnail: '',
title: JOB_NAME, link: BUILD_URL,
description: "Please Visit --> ${BASE_URL}:5000",
footer: "Jenkins Pipeline Build was a ${currentBuild.currentResult}",
result: currentBuild.currentResult
} // always
} // post
} // pipeline