This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Jenkinsfile
518 lines (490 loc) · 16.4 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#!/usr/bin/env groovy
/* Tips
1. Keep stages focused on producing one artifact or achieving one goal. This makes stages easier to parallelize or re-structure later.
1. Stages should simply invoke a make target or a self-contained script. Do not write testing logic in this Jenkinsfile.
3. CoreOS does not ship with `make`, so Docker builds still have to use small scripts.
*/
commonCreds = [
file(credentialsId: 'tectonic-license', variable: 'TF_VAR_tectonic_license_path'),
file(credentialsId: 'tectonic-pull', variable: 'TF_VAR_tectonic_pull_secret_path'),
file(credentialsId: 'GCP-APPLICATION', variable: 'GOOGLE_APPLICATION_CREDENTIALS'),
usernamePassword(
credentialsId: 'jenkins-log-analyzer-user',
passwordVariable: 'LOG_ANALYZER_PASSWORD',
usernameVariable: 'LOG_ANALYZER_USER'
),
[
$class: 'AzureCredentialsBinding',
credentialsId: 'azure-tectonic-test-service-principal',
subscriptionIdVariable: 'ARM_SUBSCRIPTION_ID',
clientIdVariable: 'ARM_CLIENT_ID',
clientSecretVariable: 'ARM_CLIENT_SECRET',
tenantIdVariable: 'ARM_TENANT_ID'
],
[
$class: 'StringBinding',
credentialsId: 'github-coreosbot',
variable: 'GITHUB_CREDENTIALS'
]
]
creds = commonCreds.collect()
creds.push(
[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'tectonic-jenkins-installer'
],
)
govcloudCreds = commonCreds.collect()
govcloudCreds.push(
usernamePassword(
credentialsId: 'tectonic-jenkins-installer-govcloud',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
usernameVariable: 'AWS_ACCESS_KEY_ID'
)
)
quayCreds = [
usernamePassword(
credentialsId: 'quay-robot',
passwordVariable: 'QUAY_ROBOT_SECRET',
usernameVariable: 'QUAY_ROBOT_USERNAME'
)
]
defaultBuilderImage = 'quay.io/coreos/tectonic-builder:v1.43'
tectonicSmokeTestEnvImage = 'quay.io/coreos/tectonic-smoke-test-env:v5.14'
originalCommitId = 'UNKNOWN'
pipeline {
agent none
environment {
KUBE_CONFORMANCE_IMAGE = 'quay.io/coreos/kube-conformance:v1.9.6_coreos.0'
LOGSTASH_BUCKET = 'log-analyzer-tectonic-installer'
}
options {
// Individual steps have stricter timeouts. 360 minutes should be never reached.
timeout(time:6, unit:'HOURS')
timestamps()
buildDiscarder(logRotator(numToKeepStr:'20', artifactNumToKeepStr: '20'))
}
parameters {
string(
name: 'builder_image',
defaultValue: defaultBuilderImage,
description: 'tectonic-builder docker image to use for builds'
)
string(
name: 'hyperkube_image',
defaultValue: '',
description: 'Hyperkube image. Please define the param like: {hyperkube="<HYPERKUBE_IMAGE>"}'
)
booleanParam(
name: 'RUN_CONFORMANCE_TESTS',
defaultValue: false,
description: ''
)
booleanParam(
name: 'RUN_SMOKE_TESTS',
defaultValue: true,
description: ''
)
booleanParam(
name: 'RUN_GUI_TESTS',
defaultValue: true,
description: ''
)
booleanParam(
name: 'PLATFORM/AWS',
defaultValue: true,
description: ''
)
booleanParam(
name: 'PLATFORM/GOVCLOUD',
defaultValue: true,
description: ''
)
booleanParam(
name: 'PLATFORM/AZURE',
defaultValue: true,
description: ''
)
/* Disabled until we start the work again on gcp
booleanParam(
name: 'PLATFORM/GCP',
defaultValue: false,
description: ''
)
*/
booleanParam(
name: 'PLATFORM/BARE_METAL',
defaultValue: true,
description: ''
)
}
stages {
stage('Build & Test') {
environment {
GO_PROJECT = '/go/src/github.com/coreos/tectonic-installer'
MAKEFLAGS = '-j4'
}
steps {
node('worker && ec2') {
script {
def err = null
try {
timeout(time: 10, unit: 'MINUTES') {
forcefullyCleanWorkspace()
checkout scm
stash name: 'clean-repo', excludes: 'installer/vendor/**,tests/smoke/vendor/**,images/tectonic-stats-extender/vendor/**'
originalCommitId = sh(returnStdout: true, script: 'git rev-parse origin/"\${BRANCH_NAME}"')
echo "originalCommitId: ${originalCommitId}"
withDockerContainer(params.builder_image) {
ansiColor('xterm') {
sh """#!/bin/bash -ex
mkdir -p \$(dirname $GO_PROJECT) && ln -sf $WORKSPACE $GO_PROJECT
cd $GO_PROJECT/
make structure-check
make bin/smoke
cd $GO_PROJECT/installer
make clean
make tools
make build
make dirtycheck
make lint
make test
rm -fr frontend/tests_output
"""
stash name: 'installer-binary', includes: 'installer/bin/linux/installer'
stash name: 'node-modules', includes: 'installer/frontend/node_modules/**'
stash name: 'smoke-test-binary', includes: 'bin/smoke'
}
}
withDockerContainer(tectonicSmokeTestEnvImage) {
sh"""#!/bin/bash -ex
cd tests/rspec
bundler exec rubocop --cache false spec lib
"""
}
}
} catch (error) {
err = error
throw error
} finally {
reportStatusToGithub((err == null) ? 'success' : 'failure', 'basic-tests', originalCommitId)
cleanWs notFailBuild: true
}
}
}
}
}
stage('GUI Tests') {
when {
expression {
return params.RUN_GUI_TESTS
}
}
environment {
TECTONIC_INSTALLER_ROLE = 'tectonic-installer'
GRAFITI_DELETER_ROLE = 'grafiti-deleter'
TF_VAR_tectonic_container_images = "${params.hyperkube_image}"
}
steps {
script {
def err = null
try {
parallel (
"IntegrationTest AWS Installer Gui": {
node('worker && ec2') {
timeout(time: 10, unit: 'MINUTES') {
forcefullyCleanWorkspace()
withCredentials(creds) {
withDockerContainer(params.builder_image) {
ansiColor('xterm') {
unstash 'clean-repo'
unstash 'installer-binary'
unstash 'node-modules'
sh """#!/bin/bash -ex
cd installer
make launch-aws-installer-guitests
make gui-aws-tests-cleanup
"""
cleanWs notFailBuild: true
}
}
}
}
}
},
"IntegrationTest Baremetal Installer Gui": {
node('worker && ec2') {
timeout(time: 10, unit: 'MINUTES') {
forcefullyCleanWorkspace()
withCredentials(creds) {
withDockerContainer(image: params.builder_image, args: '-u root') {
ansiColor('xterm') {
unstash 'clean-repo'
unstash 'installer-binary'
unstash 'node-modules'
script {
try {
sh """#!/bin/bash -ex
cd installer
make launch-baremetal-installer-guitests
"""
}
catch (error) {
throw error
}
finally {
sh """#!/bin/bash -x
cd installer
make gui-baremetal-tests-cleanup
make clean
"""
cleanWs notFailBuild: true
}
}
}
}
}
}
}
}
)
} catch (error) {
err = error
throw error
} finally {
node('worker && ec2') {
unstash 'clean-repo'
reportStatusToGithub((err == null) ? 'success' : 'failure', 'gui-tests', originalCommitId)
}
}
}
}
}
stage("Smoke Tests") {
when {
expression {
return params.RUN_SMOKE_TESTS || params.RUN_CONFORMANCE_TESTS
}
}
environment {
TECTONIC_INSTALLER_ROLE = 'tectonic-installer'
GRAFITI_DELETER_ROLE = 'grafiti-deleter'
TF_VAR_tectonic_container_images = "${params.hyperkube_image}"
TF_VAR_tectonic_kubelet_debug_config = "--minimum-container-ttl-duration=8h --maximum-dead-containers-per-container=9999 --maximum-dead-containers=9999"
GOOGLE_PROJECT = "tectonic-installer"
}
steps {
script {
def builds = [:]
def aws = [
[file: 'basic_spec.rb', args: ''],
[file: 'vpc_internal_spec.rb', args: '--device=/dev/net/tun --cap-add=NET_ADMIN -u root'],
[file: 'network_canal_spec.rb', args: ''],
[file: 'exp_spec.rb', args: ''],
[file: 'ca_spec.rb', args: ''],
[file: 'custom_tls_spec.rb', args: '']
]
def govcloud = [
[file: 'vpc_internal_spec.rb', args: '--device=/dev/net/tun --cap-add=NET_ADMIN -u root']
]
def azure = [
[file: 'basic_spec.rb', args: ''],
[file: 'private_external_spec.rb', args: '--device=/dev/net/tun --cap-add=NET_ADMIN -u root'],
/*
* Test temporarily disabled
[file: 'spec/azure_dns_spec.rb', args: ''],
*/
[file: 'external_spec.rb', args: ''],
[file: 'example_spec.rb', args: ''],
[file: 'custom_tls_spec.rb', args: '']
]
def gcp = [
/* Disabled until we start the work again on gcp
* [file: 'basic_spec.rb', args: ''],
[file: 'ha_spec.rb', args: ''],
[file: 'custom_tls_spec.rb', args: '']
*/
]
def metal = [
[file: 'basic_spec.rb', args: ''],
[file: 'custom_tls_spec.rb', args: '']
]
if (params."PLATFORM/AWS") {
aws.each { build ->
filepath = 'spec/aws/' + build.file
builds['aws/' + build.file] = runRSpecTest(filepath, build.args, creds)
}
}
if (params."PLATFORM/GOVCLOUD") {
govcloud.each { build ->
filepath = 'spec/govcloud/' + build.file
builds['govcloud/' + build.file] = runRSpecTest(filepath, build.args, govcloudCreds)
}
}
if (params."PLATFORM/AZURE") {
azure.each { build ->
filepath = 'spec/azure/' + build.file
builds['azure/' + build.file] = runRSpecTest(filepath, build.args, creds)
}
}
if (params."PLATFORM/GCP") {
gcp.each { build ->
filepath = 'spec/gcp/' + build.file
builds['gcp/' + build.file] = runRSpecTest(filepath, build.args, creds)
}
}
if (params."PLATFORM/BARE_METAL") {
metal.each { build ->
filepath = 'spec/metal/' + build.file
builds['metal/' + build.file] = runRSpecTestBareMetal(filepath, creds)
}
}
parallel builds
}
}
}
stage('Build docker image') {
when {
branch 'master'
}
steps {
node('worker && ec2') {
forcefullyCleanWorkspace()
withCredentials(quayCreds) {
ansiColor('xterm') {
unstash 'clean-repo'
sh """
docker build -t quay.io/coreos/tectonic-installer:master -f images/tectonic-installer/Dockerfile .
docker login -u="$QUAY_ROBOT_USERNAME" -p="$QUAY_ROBOT_SECRET" quay.io
docker push quay.io/coreos/tectonic-installer:master
docker logout quay.io
"""
cleanWs notFailBuild: true
}
}
}
}
}
}
post {
always {
node('worker && ec2') {
forcefullyCleanWorkspace()
echo "Starting with streaming the logfile to the S3 bucket"
withDockerContainer(params.builder_image) {
withCredentials(creds) {
unstash 'clean-repo'
sh """#!/bin/bash -xe
export BUILD_RESULT=${currentBuild.currentResult}
./tests/jenkins-jobs/scripts/log-analyzer-copy.sh jenkins-logs
"""
}
}
}
}
}
}
def forcefullyCleanWorkspace() {
return withDockerContainer(
image: tectonicSmokeTestEnvImage,
args: '-u root'
) {
ansiColor('xterm') {
sh """#!/bin/bash -e
if [ -d "\$WORKSPACE" ]
then
rm -rfv \$WORKSPACE/*
fi
"""
}
}
}
def runRSpecTest(testFilePath, dockerArgs, credentials) {
return {
node('worker && ec2') {
def err = null
try {
timeout(time: 5, unit: 'HOURS') {
forcefullyCleanWorkspace()
ansiColor('xterm') {
withCredentials(credentials + quayCreds) {
withDockerContainer(
image: tectonicSmokeTestEnvImage,
args: '-u root -v /var/run/docker.sock:/var/run/docker.sock ' + dockerArgs
) {
unstash 'clean-repo'
unstash 'smoke-test-binary'
sh """#!/bin/bash -ex
mkdir -p templogfiles && chmod 777 templogfiles
cd tests/rspec
# Directing test output both to stdout as well as a log file
rspec ${testFilePath} --format RspecTap::Formatter --format RspecTap::Formatter --out ../../templogfiles/format=tap.log
"""
}
}
}
}
} catch (error) {
err = error
throw error
} finally {
reportStatusToGithub((err == null) ? 'success' : 'failure', testFilePath, originalCommitId)
archiveArtifacts allowEmptyArchive: true, artifacts: 'build/**/logs/**'
withDockerContainer(params.builder_image) {
withCredentials(creds) {
sh """#!/bin/bash -xe
./tests/jenkins-jobs/scripts/log-analyzer-copy.sh smoke-test-logs ${testFilePath}
"""
}
}
cleanWs notFailBuild: true
}
}
}
}
def runRSpecTestBareMetal(testFilePath, credentials) {
return {
node('worker && bare-metal') {
def err = null
try {
timeout(time: 4, unit: 'HOURS') {
ansiColor('xterm') {
unstash 'clean-repo'
unstash 'smoke-test-binary'
withCredentials(credentials + quayCreds) {
sh """#!/bin/bash -ex
cd tests/rspec
export RBENV_ROOT=/usr/local/rbenv
export PATH="/usr/local/rbenv/bin:$PATH"
eval \"\$(rbenv init -)\"
rbenv install -s
gem install bundler
bundler install
bundler exec rspec ${testFilePath} --format RspecTap::Formatter --format RspecTap::Formatter --out ../../templogfiles/format=tap.log
"""
}
}
}
} catch (error) {
err = error
throw error
} finally {
reportStatusToGithub((err == null) ? 'success' : 'failure', testFilePath, originalCommitId)
archiveArtifacts allowEmptyArchive: true, artifacts: 'build/**/logs/**'
withCredentials(credentials) {
sh """#!/bin/bash -xe
./tests/jenkins-jobs/scripts/log-analyzer-copy.sh smoke-test-logs ${testFilePath}
"""
}
cleanWs notFailBuild: true
}
}
}
}
def reportStatusToGithub(status, context, commitId) {
withCredentials(creds) {
sh """#!/bin/bash -ex
./tests/jenkins-jobs/scripts/report-status-to-github.sh ${status} ${context} ${commitId}
"""
}
}