-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
253 lines (249 loc) · 7.44 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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/env groovy
@Library('[email protected]') _
pipeline {
agent any
parameters {
booleanParam(
name: 'forceEndToEnd',
defaultValue: false,
description: 'When true, forces the end-to-end tests to always run.')
}
environment {
dockerImage = null
PROJ_NAME = projName()
GIT_DESCRIPTION = gitDescription()
DOCKER_IMG = dockerImageName("${LCO_DOCK_REG}", "${PROJ_NAME}", "${GIT_DESCRIPTION}")
}
options {
timeout(time: 3, unit: 'HOURS')
lock resource: 'BANZAINRESLock'
}
stages {
stage('Build image') {
steps {
script {
dockerImage = docker.build("${DOCKER_IMG}", "--pull .")
}
}
}
stage('Push image') {
steps {
script {
dockerImage.push("${GIT_DESCRIPTION}")
}
}
}
stage('Unit Tests') {
steps {
script {
sh 'docker run --rm --user=root --entrypoint=pytest ${DOCKER_IMG} -m "not e2e" /lco/banzai-nres/'
}
}
}
stage('DeployProdStack') {
agent {
label 'helm'
}
when {
buildingTag();
}
steps {
script {
withKubeConfig([credentialsId: "prod-kube-config"]) {
sh('helm repo update && helm dependency update helm-chart/banzai-nres/ '+
'&& helm package helm-chart/banzai-nres --app-version="${GIT_DESCRIPTION}" --version="${GIT_DESCRIPTION}" ' +
'&& helm upgrade --install banzai-nres banzai-nres-"${GIT_DESCRIPTION}".tgz --namespace=prod ' +
'--set image.tag="${GIT_DESCRIPTION}" --values=helm-chart/banzai-nres/values-prod.yaml ' +
'--force --atomic --timeout=3600s')
}
}
}
}
stage('DeployTestStack') {
agent {
label 'helm'
}
when {
anyOf {
branch 'PR-*'
branch 'dev'
expression { return params.forceEndToEnd }
}
}
steps {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
if (env.BRANCH_NAME == "dev") {
dataTag = '1.0.4'
} else {
dataTag = '1.0.4-slim'
}
sh('helm repo update')
final cmd = " helm delete --namespace=build --purge banzai-nres-e2e &> cleanup.txt"
final status = sh(script: cmd, returnStatus: true)
final output = readFile('cleanup.txt').trim()
sh(script: "rm -f cleanup.txt", returnStatus: true)
echo output
sh(script: "kubectl delete pvc banzai-nres-e2e --wait=true --timeout=600s", returnStatus: true)
sh('helm upgrade --namespace=build --install banzai-nres-e2e helm-chart/banzai-nres-e2e ' +
'--set banzaiNRES.tag="${GIT_DESCRIPTION}" --set dataImage.tag=' + dataTag +
' --force --wait --timeout=3600s')
podName = sh(script: 'kubectl get po -l app.kubernetes.io/instance=banzai-nres-e2e ' +
'--sort-by=.status.startTime -o jsonpath="{.items[-1].metadata.name}"',
returnStdout: true).trim()
}
}
}
}
stage('Test-Master-Bias-Creation') {
when {
anyOf {
branch 'PR-*'
expression { return params.forceEndToEnd }
}
}
steps {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl exec ${podName} -c banzai-nres-e2e-listener -- " +
"pytest -s --durations=0 --junitxml=/home/archive/pytest-master-bias.xml " +
"-m master_bias /lco/banzai-nres/")
}
}
}
post {
always {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl cp -c banzai-nres-e2e-listener ${podName}:/home/archive/pytest-master-bias.xml " +
"pytest-master-bias.xml")
junit "pytest-master-bias.xml"
}
}
}
}
}
stage('Test-Master-Dark-Creation') {
when {
anyOf {
branch 'PR-*'
expression { return params.forceEndToEnd }
}
}
steps {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl exec ${podName} -c banzai-nres-e2e-listener -- " +
"pytest -s --durations=0 --junitxml=/home/archive/pytest-master-dark.xml " +
"-m master_dark /lco/banzai-nres/")
}
}
}
post {
always {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl cp -c banzai-nres-e2e-listener ${podName}:/home/archive/pytest-master-dark.xml " +
"pytest-master-dark.xml")
junit "pytest-master-dark.xml"
}
}
}
}
}
stage('Test-Master-Flat-Creation') {
when {
anyOf {
branch 'PR-*'
expression { return params.forceEndToEnd }
}
}
steps {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl exec ${podName} -c banzai-nres-e2e-listener -- " +
"pytest -s --durations=0 --junitxml=/home/archive/pytest-master-flat.xml " +
"-m master_flat /lco/banzai-nres/")
}
}
}
post {
always {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl cp -c banzai-nres-e2e-listener ${podName}:/home/archive/pytest-master-flat.xml " +
"pytest-master-flat.xml")
junit "pytest-master-flat.xml"
}
}
}
}
}
stage('Test-Master-Arc-Creation') {
when {
anyOf {
branch 'PR-*'
expression { return params.forceEndToEnd }
}
}
steps {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl exec ${podName} -c banzai-nres-e2e-listener -- " +
"pytest -s --durations=0 --junitxml=/home/archive/pytest-master-arc.xml " +
"-m master_arc /lco/banzai-nres/")
}
}
}
post {
always {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl cp -c banzai-nres-e2e-listener ${podName}:/home/archive/pytest-master-arc.xml " +
"pytest-master-arc.xml")
junit "pytest-master-arc.xml"
}
}
}
}
}
stage('Test-Science-Frame-Creation') {
agent {
label 'helm'
}
when {
anyOf {
branch 'PR-*'
expression { return params.forceEndToEnd }
}
}
steps {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl exec ${podName} -c banzai-nres-e2e-listener -- " +
"pytest -s --durations=0 --junitxml=/home/archive/pytest-science-frames.xml " +
"-m science_frames /lco/banzai-nres/")
}
}
}
post {
always {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("kubectl cp -c banzai-nres-e2e-listener ${podName}:/home/archive/pytest-science-frames.xml " +
"pytest-science-frames.xml")
junit "pytest-science-frames.xml"
}
}
}
success {
script {
withKubeConfig([credentialsId: "build-kube-config"]) {
sh("helm delete --namespace=build banzai-nres-e2e --purge || true")
}
}
}
}
}
}
}