forked from cliqz-oss/browser-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
325 lines (276 loc) · 11.2 KB
/
Jenkinsfile
File metadata and controls
325 lines (276 loc) · 11.2 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
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
#!/bin/env groovy
import groovy.time.*
@Library('cliqz-shared-library@v1.2') _
properties([
[$class: 'JobRestrictionProperty'],
parameters([
string(name: 'DOCKER_REGISTRY_URL', defaultValue: '141047255820.dkr.ecr.us-east-1.amazonaws.com'),
string(name: 'AWS_REGION', defaultValue: 'us-east-1'),
]),
])
def matrix = [
'unit tests': [
'gpu': false,
'config': 'configs/ci/unit-tests.js',
'testParams': '-l unit-node',
],
'browser: content': [
'gpu': true,
'config': 'configs/ci/browser.js',
'testParams': '-l chromium',
],
'firefox 52': [
'gpu': true,
'config': 'configs/ci/browser.js',
'testParams': '-l firefox-web-ext --firefox ~/firefox52/firefox/firefox',
],
'firefox 60': [
'gpu': true,
'config': 'configs/ci/browser.js',
'testParams': '-l firefox-web-ext --firefox ~/firefox60/firefox/firefox',
],
'firefox beta': [
'gpu': true,
'config': 'configs/ci/browser.js',
'testParams': '-l firefox-web-ext --firefox ~/firefoxBeta/firefox/firefox',
],
'firefox nightly': [
'gpu': true,
'config': 'configs/ci/browser.js',
'testParams': '-l firefox-web-ext --firefox ~/firefoxNightly/firefox/firefox',
],
/*
'firefox stresstest (52)': [
'gpu': true,
'config': 'configs/ci/browser.js',
'testParams': '-l firefox-web-ext-stresstest --firefox ~/firefox52/firefox/firefox',
],
*/
'webextension': [
'gpu': true,
'config': 'configs/ci/webextension.js',
'testParams': '-l chromium-selenium',
],
'ghostery': [
'gpu': false,
'config': 'configs/ci/ghostery.js',
'testParams': '-l ghostery-selenium',
],
'react-native': [
'gpu': false,
'config':'configs/ci/react-native.js',
'testParams': '-l react-native',
],
]
String triggeringCommitHash = github.getCommitHash()
String currentCommitHash
String codeDockerImage
def setGithubCommitStatus(commit, context, status, message) {
withCredentials([[
$class: 'StringBinding',
credentialsId: '5d3e0a3c-2490-491b-8a67-aa5eab2f27f2',
variable: 'GITHUB_TOKEN'
]]) {
github.setCommitStatus(
env.GITHUB_TOKEN,
'cliqz/navigation-extension',
commit,
context,
status,
message
)
}
}
parallel helpers.entries(matrix).collectEntries {
[("Github Status ${it[0]}"): {
setGithubCommitStatus(triggeringCommitHash, it[0], 'pending', 'pending')
}]
}
node('docker && !gpu && us-east-1') {
stage('checkout') {
def scmInfo = checkout scm
currentCommitHash = scmInfo.GIT_COMMIT
codeDockerImage = "navigation-extension/tests:${currentCommitHash}"
}
def dockerfileChecksum = sh(returnStdout: true, script: 'md5sum Dockerfile.ci | cut -d" " -f1').trim()
def packageJsonChecksum = sh(returnStdout: true, script: 'md5sum package.json | cut -d" " -f1').trim()
// add date to the tag in order to download FF beta and nightly at least once per day and stay up-to-date
def today = new Date().format('yyyyMMdd')
def dockerTag = "${dockerfileChecksum}-${packageJsonChecksum}-${today}"
// authorize docker deamon to access registry - no longer needed for GP nodes
// sh "`aws ecr get-login --no-include-email --region=${params.AWS_REGION}`"
docker.withRegistry("https://${params.DOCKER_REGISTRY_URL}") {
stage('prepare docker base image') {
ansiColor('xterm') {
def baseImageName = "navigation-extension/build:${dockerTag}"
try {
def image = docker.image(baseImageName)
image.pull()
} catch (e) {
print e
def baseImage = docker.build(
baseImageName,
'-f Dockerfile.ci .'
)
baseImage.push dockerTag
}
}
}
stage('prepare docker code image') {
writeFile file: 'Dockerfile.code', text: """
FROM ${params.DOCKER_REGISTRY_URL}/navigation-extension/build:${dockerTag}
COPY --chown=node:node . /app/
"""
def codeImage = docker.build(
codeDockerImage,
'-f Dockerfile.code .'
)
codeImage.push currentCommitHash
}
}
}
def build(Map m) {
def context = m.context
def getCodeDockerImage = m.getCodeDockerImage
def config = m.config
def stashName = "${env.JOB_BASE_NAME}_${env.BUILD_NUMBER}_${config.bytes.encodeBase64().toString()}"
echo "Saving to stash ${stashName} #1"
return {
node('docker && !gpu && us-east-1') {
def codeDockerImage = getCodeDockerImage()
stage('Build an image') {
docker.withRegistry("https://${params.DOCKER_REGISTRY_URL}") {
def image = docker.image(codeDockerImage)
image.pull()
withEnv(["CLIQZ_CONFIG_PATH=${config}",
"CLIQZ_OUTPUT_PATH=${env.WORKSPACE}/${stashName}"
]) {
docker.image(image.imageName()).inside() {
sh """#!/bin/bash
set -x
cd /app
./fern.js build --environment testing
"""
}
stash includes: "${stashName}/**/*", name: "${stashName}"
}
}
}
}
}
}
def test(Map m) {
def context = m.context
def config = m.config
def testParams = m.testParams
def gpu = m.gpu
def stashName = "${env.JOB_BASE_NAME}_${env.BUILD_NUMBER}_${config.bytes.encodeBase64().toString()}"
def getCodeDockerImage = m.getCodeDockerImage
def getTriggeringCommitHash = m.getTriggeringCommitHash
def nodeLabels = gpu ? 'us-east-1 && docker && gpu' : 'us-east-1 && docker && !gpu'
return {
node(nodeLabels) {
def codeDockerImage = getCodeDockerImage()
def triggeringCommitHash = getTriggeringCommitHash()
def HOST = helpers.getIp()
def VNC_PORT = helpers.getFreePort(lower: 20000, upper: 20999)
def dockerParams = "-p ${VNC_PORT}:5900 --add-host cliqztest.com:127.0.0.1"
if (gpu) {
dockerParams += ' --device /dev/nvidia0 --device /dev/nvidiactl --cpus=2'
}
// authorize docker deamon to access registry - no longer needed for GP nodes
// sh "`aws ecr get-login --no-include-email --region=${params.AWS_REGION}`"
docker.withRegistry("https://${params.DOCKER_REGISTRY_URL}") {
def image = docker.image(codeDockerImage)
stage('tests: get image') {
image.pull()
}
withEnv(["CLIQZ_CONFIG_PATH=${config}"]) {
dir("${stashName}") {
unstash name: "${stashName}"
}
docker.image(image.imageName()).inside(dockerParams) {
setGithubCommitStatus(
triggeringCommitHash,
context,
'pending',
"VNC ${HOST}:${VNC_PORT}"
)
timeout(25) {
stage('tests: run') {
def report
def hasErrors
try {
def timeBefore = new Date()
sh """#!/bin/bash
set -x
cd /app
cp -r ${env.WORKSPACE}/${stashName}/${stashName} build
rm -f report.xml
export DISPLAY=:0
Xvfb \$DISPLAY -screen 0 1024x768x24 -ac &
openbox&
x11vnc -storepasswd vnc /tmp/vncpass
x11vnc -rfbport 5900 -rfbauth /tmp/vncpass -forever > /dev/null 2>&1 &
./fern.js test ${testParams} --no-build --environment testing --ci report.xml > /dev/null; true
cp report.xml ${env.WORKSPACE}
"""
def timeAfter = new Date()
def duration = "${TimeCategory.minus(timeAfter, timeBefore).getHours()}h, ${TimeCategory.minus(timeAfter, timeBefore).getMinutes()}m"
Map r = xunit.parse('/app/report.xml')
if (!r.containsKey('errors')) {
r.errors = '0'
}
report = "tests: ${r.tests}, f/e: ${r.failures}/${r.errors}, time: ${duration}"
hasErrors = (r.failures != '0') || (r.errors != '0')
if (r.tests == '0') {
throw new Exception('No tests have been run!')
}
junit(
allowEmptyResults: true,
healthScaleFactor: 0.0,
testResults: 'report.xml'
)
} catch (e) {
report = e
hasErrors = true
}
setGithubCommitStatus(
triggeringCommitHash,
context,
hasErrors ? 'failure' : 'success',
report
)
} // end stage
} // end timeout
} // end docker
}
}
}
}
}
def getStepsForParallel(matrix) {
def buildSteps = [:]
matrix.each { name, params ->
buildSteps[params.get('config')] = 1
}
return buildSteps
}
def stepsForParallelTests = helpers.entries(matrix).collectEntries {
[(it[0]): test(
context: it[0],
config: it[1]['config'],
testParams: it[1]['testParams'],
gpu: it[1]['gpu'],
getCodeDockerImage: { codeDockerImage },
getTriggeringCommitHash: { triggeringCommitHash }
)]
}
def stepsForParallelBuilds = helpers.entries(getStepsForParallel(matrix)).collectEntries {
[("Build ${it[0]}"): build(
config: it[0],
getCodeDockerImage: { codeDockerImage }
)]
}
parallel stepsForParallelBuilds
parallel stepsForParallelTests