forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.cd
281 lines (241 loc) · 9.84 KB
/
Jenkinsfile.cd
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
#!groovy
@Library('[email protected]') _
String name = 'indy-node'
String pkgName = name
def nodeTestUbuntu = {
try {
echo 'Ubuntu Test: Checkout csm'
checkout scm
echo 'Ubuntu Test: Build docker image'
def testEnv = dockerHelpers.build(name)
testEnv.inside('--network host') {
echo 'Ubuntu Test: Install dependencies'
testHelpers.install()
echo 'Ubuntu Test: Test'
testHelpers.testRunner([resFile: "test-result-node.${NODE_NAME}.txt", testDir: 'indy_node'])
//testHelpers.testJUnit(resFile: "test-result-node.${NODE_NAME}.xml")
}
}
finally {
echo 'Ubuntu Test: Cleanup'
step([$class: 'WsCleanup'])
}
}
def commonTestUbuntu = {
try {
echo 'Ubuntu Test: Checkout csm'
checkout scm
echo 'Ubuntu Test: Build docker image'
def testEnv = dockerHelpers.build(name)
testEnv.inside {
echo 'Ubuntu Test: Install dependencies'
testHelpers.install()
echo 'Ubuntu Test: Test'
testHelpers.testJUnit([resFile: "test-result-common.${NODE_NAME}.xml", testDir: 'indy_common'])
}
}
finally {
echo 'Ubuntu Test: Cleanup'
step([$class: 'WsCleanup'])
}
}
def buildDebUbuntu = { releaseVersion, sourcePath, packageVersion=null, missedPkgs=false ->
def volumeName = "$name-deb-u1604"
packageVersion = packageVersion ?: releaseVersion
if (env.BRANCH_NAME != '' && env.BRANCH_NAME != 'master') {
volumeName = "${volumeName}.${BRANCH_NAME}"
}
if (sh(script: "docker volume ls -q | grep -q '^$volumeName\$'", returnStatus: true) == 0) {
sh "docker volume rm $volumeName"
}
// TODO build only missed ones
dir('build-scripts/ubuntu-1604') {
sh "./build-$name-docker.sh \"$sourcePath\" $releaseVersion $volumeName $packageVersion"
if (missedPkgs == [pkgName]) {
echo "Skip 3rd parties building"
} else {
sh "./build-3rd-parties-docker.sh $volumeName"
}
}
return "$volumeName"
}
def systemTests = { component, releaseVersion ->
String prefix = "System Tests ($component)"
String systemTestsNetwork = 'indy-test-automation-network'
String systemTestsDir = './system_tests'
List testsSchema = [
['test_ledger.py'],
['test_vc.py'],
['test_consensus.py', 'TestTAASuite.py'],
['test_upgrade.py', 'test_roles.py', 'test_freshness.py', 'TestMultiSigSuite.py']
]
Map indyPlenumVersions = [:]
Map indySDKVersions = [:]
Map indyCryptoVersions = [:]
def dockerClean = {
sh "./system/docker/clean.sh $systemTestsNetwork"
try {
sh "docker ps -q --filter network=$systemTestsNetwork | xargs -r docker rm -f"
} catch (Exception exc) {
echo "$prefix: failed to remove docker containers in $systemTestsNetwork network: $exc"
throw exc
}
try {
sh "docker network ls -q --filter name=$systemTestsNetwork | xargs -r docker network rm"
} catch (Exception exc) {
echo "$prefix: failed to remove docker $systemTestsNetwork network: $exc"
throw exc
}
sh "docker container prune -f"
sh "docker network prune -f"
}
def runTest = { testGroup ->
stage("[${testGroup}] Checkout system tests") {
testHelpers.getSystemTests(tag: 'v0.7.0', targetDir: systemTestsDir)
}
dir(systemTestsDir) {
stage("[${testGroup}] Patch system tests python requirements") {
sh """
sed -i 's/python3-indy.*/python3-indy==${indySDKVersions.pypi}/g' ./system/requirements.txt
#sed -i 's/indy-plenum.*/indy-plenum==${indyPlenumVersions.pypi}/g' ./system/requirements.txt
#sed -i 's/indy-crypto.*/indy-crypto==${indyCryptoVersions.pypi}/g' ./system/requirements.txt
"""
}
stage("[${testGroup}] Cleanup docker") {
dockerClean()
}
stage("[${testGroup}] Prepare docker env") {
withEnv([
"INDY_NODE_REPO_COMPONENT=$component",
"LIBINDY_CRYPTO_VERSION=${indyCryptoVersions.debian}",
"PYTHON3_LIBINDY_CRYPTO_VERSION=${indyCryptoVersions.debian}",
"INDY_PLENUM_VERSION=${indyPlenumVersions.debian}",
"INDY_NODE_VERSION=$releaseVersion",
"LIBINDY_REPO_COMPONENT=${indySDKVersions.debian == indySDKVersions.pypi ? 'stable' : 'master'}",
"LIBINDY_VERSION=${indySDKVersions.debian}",
]) {
sh "./system/docker/prepare.sh $systemTestsNetwork"
}
}
try {
def err
String testReportFileNameXml = "system_tests_${testGroup}_report.${component}.xml"
String testReportFileNamePlain = "system_tests_${testGroup}_report.${component}.txt"
String testTargets = testsSchema[testGroup].collect{"system/indy-node-tests/$it"}.join(' ')
try {
stage("[${testGroup}] Run tests") {
sh """
bash -c "\
set -o pipefail; \
./system/docker/run.sh \
\\"$testTargets\\" \
\\"-l -vv --junit-xml=$testReportFileNameXml\\" \
\\"$systemTestsNetwork\\" 2>&1 | tee $testReportFileNamePlain;\
"
"""
}
} catch (_err) {
err = _err
throw _err
} finally {
stage("[${testGroup}] Upload test report") {
sh "ls -la *report* || true"
if (err) {
archiveArtifacts artifacts: testReportFileNamePlain, allowEmptyArchive: true
}
junit testResults: testReportFileNameXml, allowEmptyResults: true
}
}
} catch (Exception exc) {
echo "$prefix: fail: $exc"
throw exc
} finally {
stage("[${testGroup}] Cleanup docker") {
dockerClean()
}
}
}
}
nodeWrapper("ubuntu") {
stage("Checkout SCM") {
checkout scm
}
stage("Get versions of dependencies") {
String pipLogName = "pip.intsall.log"
def uid = sh(returnStdout: true, script: 'id -u').trim()
docker.build("hyperledger/indy-node-ci", "--build-arg uid=$uid -f ci/ubuntu.dockerfile ci").inside {
sh """
pip install .[tests] >$pipLogName
"""
indyPlenumVersions.pypi = sh(returnStdout: true, script: """
grep "^Collecting indy-plenum==" $pipLogName | awk '{print \$2}' | awk -F'==' '{print \$2}'
""").trim()
indyPlenumVersions.debian = indyPlenumVersions.pypi.replaceAll(/\.?(dev|rc)(.*)/, "~\$1\$2")
echo "indy-plenum versions: $indyPlenumVersions"
indySDKVersions.pypi = sh(returnStdout: true, script: """
grep "^Collecting python3-indy==" $pipLogName | awk '{print \$2}' | awk -F'==' '{print \$2}'
""").trim()
indySDKVersions.debian = indySDKVersions.pypi.replaceAll(/-(dev|rc)-(.*)/, "~\$2")
echo "indy-sdk version: ${indySDKVersions}"
indyCryptoVersions.pypi = sh(returnStdout: true, script: """
grep "^Collecting indy-crypto==" $pipLogName | awk '{print \$2}' | awk -F'==' '{print \$2}'
""").trim()
indyCryptoVersions.debian = indyCryptoVersions.pypi.replaceAll(/-(dev|rc)-(.*)/, "~\$2")
echo "indy-crypto version: ${indyCryptoVersions}"
}
if (!(indyPlenumVersions.debian && indySDKVersions.debian && indyCryptoVersions.debian)) {
error "Failed to get versions for indy-plenum or indy-crypto or indy-sdk"
}
}
Map builds = [:]
for (int i = 0; i < testsSchema.size(); i++) {
String testNames = testsSchema[i].join(' ')
Boolean isFirst = (i == 0)
int testGroup = i
builds[testNames] = {
stage("Run ${testNames}") {
if (isFirst) {
runTest(testGroup)
} else {
nodeWrapper('ubuntu') {
runTest(testGroup)
}
}
}
}
}
builds.failFast = false
parallel builds
}
}
def options = new TestAndPublishOptions()
options.setPkgName(pkgName)
options.setApprovers(['QA'])
options.setNotifEmails([
QA: [
to: "${env.INDY_NODE_QA_RECIPIENTS ?: ''}",
cc: "${env.INDY_NODE_RECIPIENTS ?: ''}"
],
success: [
to: "${env.INDY_NODE_RECIPIENTS ?: ''}"
],
fail: [
to: "${env.INDY_NODE_RECIPIENTS ?: ''}"
]
])
// TODO duplicates list from build scripts
options.setBuiltPkgs([
'python3-timeout-decorator': '0.4.0',
'python3-distro': '1.3.0',
])
options.enable([StagesEnum.PACK_RELEASE_COPY, StagesEnum.PACK_RELEASE_COPY_ST])
options.setCopyWithDeps(true)
options.setSystemTestsCb(systemTests)
options.setPrContexts([env.INDY_GITHUB_PR_REQUIRED_CONTEXT ?: "ci/hyperledger-jenkins/pr-merge"])
testAndPublish(
name,
[
ubuntu: [node: nodeTestUbuntu, common: commonTestUbuntu]
],
true, options, [ubuntu: buildDebUbuntu], 'indy_node'
)