forked from coreos/tectonic-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
476 lines (452 loc) · 15.3 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
#!/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.
*/
creds = [
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: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'tectonic-jenkins-installer'
],
[
$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'
]
]
quayCreds = [
usernamePassword(
credentialsId: 'quay-robot',
passwordVariable: 'QUAY_ROBOT_SECRET',
usernameVariable: 'QUAY_ROBOT_USERNAME'
)
]
defaultBuilderImage = 'quay.io/coreos/tectonic-builder:v1.41'
tectonicSmokeTestEnvImage = 'quay.io/coreos/tectonic-smoke-test-env:v5.9_tap'
originalCommitId = 'UNKNOWN'
pipeline {
agent none
environment {
KUBE_CONFORMANCE_IMAGE = 'quay.io/coreos/kube-conformance:v1.8.2_coreos.0'
LOGSTASH_BUCKET = 'log-analyzer-tectonic-installer'
}
options {
// Individual steps have stricter timeouts. 300 minutes should be never reached.
timeout(time:5, 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/AZURE',
defaultValue: true,
description: ''
)
booleanParam(
name: 'PLATFORM/GCP',
defaultValue: true,
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}"
printLogstashAttributes()
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: '']
]
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: 'self_hosted_etcd_spec.rb', args: ''],
[file: 'external_self_hosted_etcd_spec.rb', args: '']
]
def gcp = [
[file: 'basic_spec.rb', args: ''],
[file: 'ha_spec.rb', args: ''],
]
if (params."PLATFORM/AWS") {
aws.each { build ->
filepath = 'spec/aws/' + build.file
builds['aws/' + build.file] = runRSpecTest(filepath, build.args)
}
}
if (params."PLATFORM/AZURE") {
azure.each { build ->
filepath = 'spec/azure/' + build.file
builds['azure/' + build.file] = runRSpecTest(filepath, build.args)
}
}
if (params."PLATFORM/GCP") {
gcp.each { build ->
filepath = 'spec/gcp/' + build.file
builds['gcp/' + build.file] = runRSpecTest(filepath, build.args)
}
}
if (params."PLATFORM/BARE_METAL") {
builds['bare_metal'] = {
node('worker && bare-metal') {
def err = null
def specFile = 'spec/metal/basic_spec.rb'
try {
timeout(time: 4, unit: 'HOURS') {
ansiColor('xterm') {
unstash 'clean-repo'
unstash 'smoke-test-binary'
withCredentials(creds) {
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 $specFile --format RspecTap::Formatter
"""
}
}
}
} catch (error) {
err = error
throw error
} finally {
reportStatusToGithub((err == null) ? 'success' : 'failure', specFile, originalCommitId)
archiveArtifacts allowEmptyArchive: true, artifacts: 'tests/rspec/logs/**/*.log'
cleanWs notFailBuild: true
}
}
}
}
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
./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) {
return {
node('worker && ec2') {
def err = null
try {
timeout(time: 4, unit: 'HOURS') {
forcefullyCleanWorkspace()
ansiColor('xterm') {
withCredentials(creds) {
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
cd tests/rspec
bundler exec rspec ${testFilePath} --format RspecTap::Formatter
"""
}
}
}
}
} catch (error) {
err = error
throw error
} finally {
reportStatusToGithub((err == null) ? 'success' : 'failure', testFilePath, originalCommitId)
archiveArtifacts allowEmptyArchive: true, artifacts: 'tests/rspec/logs/**/*.log'
withDockerContainer(params.builder_image) {
withCredentials(creds) {
sh """#!/bin/bash -xe
./tests/jenkins-jobs/scripts/log-analyzer-copy.sh smoke-test-logs
"""
}
}
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}
"""
}
}
//Function used to print environment variables that are used by Logstash as attributes for the log file.
def printLogstashAttributes() {
echo "Build_Number=" + env.BUILD_NUMBER
echo "JOB_NAME=" + env.JOB_NAME
echo "USER_REQUEST=" + env.CHANGE_AUTHOR
echo "GIT_TARGET_BRANCH=" + env.CHANGE_TARGET
echo "GIT_PR_NUMBER=" + env.CHANGE_ID
}