forked from hyperledger-archives/indy-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.ci
456 lines (386 loc) · 16.8 KB
/
Jenkinsfile.ci
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
#!groovy
testing()
def testing() {
stage('Testing') {
parallel([
'ubuntu-test' : { ubuntuTesting() },
'macos-test' : { macosTesting() },
'ios-test' : { iosTesting() },
'redhat-test' : { rhelTesting() },
'windows-test': { windowsTesting() }
])
}
}
def windowsTesting() {
node('win2016') {
stage('Windows Test') {
def ws_path = "workspace/${env.JOB_NAME}".replace(' ', '_')
ws(ws_path) {
try {
echo "Windows Test: Checkout scm"
checkout scm
echo "Windows Test: Run Indy pool"
bat "docker -H $INDY_SDK_SERVER_IP build --build-arg pool_ip=$INDY_SDK_SERVER_IP -f ci/indy-pool.dockerfile -t indy_pool ci"
bat "docker -H $INDY_SDK_SERVER_IP run -d --network host --name indy_pool -p 9701-9708:9701-9708 indy_pool"
setupRust()
dir('libindy') {
echo "Windows Test: Download prebuilt dependencies"
bat 'wget -O prebuilt.zip "https://repo.sovrin.org/windows/libindy/deps/indy-sdk-deps.zip"'
bat 'unzip prebuilt.zip -d prebuilt'
echo "Windows Libindy Test: Build"
withEnv([
"INDY_PREBUILT_DEPS_DIR=$WORKSPACE\\libindy\\prebuilt",
"INDY_CRYPTO_PREBUILT_DEPS_DIR=$WORKSPACE\\libindy\\prebuilt",
"MILAGRO_DIR=$WORKSPACE\\libindy\\prebuilt",
"LIBZMQ_PREFIX=$WORKSPACE\\libindy\\prebuilt",
"SODIUM_LIB_DIR=$WORKSPACE\\libindy\\prebuilt",
"OPENSSL_DIR=$WORKSPACE\\libindy\\prebuilt",
"PATH=$WORKSPACE\\libindy\\prebuilt\\lib;$PATH",
"RUST_BACKTRACE=1"
]) {
bat "cargo build --features fatal_warnings"
bat "cargo test --no-run"
echo "Windows Libindy Test: Run tests"
withEnv([
"RUST_TEST_THREADS=1",
"RUST_LOG=indy::=debug,zmq=trace",
"TEST_POOL_IP=$INDY_SDK_SERVER_IP"
]) {
bat "cargo test"
}
}
}
dir('libnullpay') {
echo "Windows Libnullpay Test: Build"
withEnv([
"RUST_BACKTRACE=1"
]) {
bat "cargo build --features fatal_warnings"
bat "cargo test --no-run"
echo "Windows Libnullpay Test: Run tests"
withEnv([
"RUST_TEST_THREADS=1",
"RUST_LOG=indy::=debug,zmq=trace",
"TEST_POOL_IP=$INDY_SDK_SERVER_IP",
"PATH=$WORKSPACE\\libindy\\target\\debug;$PATH",
]) {
bat "cargo test"
}
}
}
bat "copy $WORKSPACE\\libnullpay\\target\\debug\\nullpay.dll $WORKSPACE\\cli"
dir('cli') {
bat "sed -i -e \"s/10\\.0\\.0\\.2/${INDY_SDK_SERVER_IP}/g\" docker_pool_transactions_genesis"
def featuresArgs = '--features "nullpay_plugin"'
echo "Windows Indy Cli Test: Build"
withEnv([
"RUST_BACKTRACE=1"
]) {
bat "cargo test $featuresArgs --no-run"
echo "Windows Indy Cli Test: Run tests"
withEnv([
"RUST_TEST_THREADS=1",
"RUST_LOG=indy::=debug,zmq=trace",
"TEST_POOL_IP=$INDY_SDK_SERVER_IP"
]) {
bat "cargo test $featuresArgs"
}
}
}
//TODO wrappers testing
} finally {
try {
bat "docker -H $INDY_SDK_SERVER_IP stop indy_pool"
} catch (ignore) {
}
try {
bat "docker -H $INDY_SDK_SERVER_IP rm indy_pool"
} catch (ignore) {
}
cleanWs()
}
}
cleanWs()
}
}
}
def macosTesting() {
node('macos') {
stage('MacOS Test') {
try {
echo "MacOS Test: Checkout scm"
checkout scm
dir('libindy') {
echo "MacOS Test: Build"
setupRust()
setupBrewPackages()
sh "cargo build --features fatal_warnings"
sh "cargo test --no-run"
// TODO testing
}
//TODO wrappers testing
} finally {
step([$class: 'WsCleanup'])
}
}
}
}
def iosTesting() {
node('macos') {
stage('iOS Test') {
try {
echo "iOS Test: Checkout scm"
checkout scm
echo "iOS Test: Running pool"
sh "docker rm -f indy_pool || true"
sh "docker build -f ci/indy-pool.dockerfile -t indy_pool ci"
sh "docker run -d --name indy_pool -p 9701-9708:9701-9708 indy_pool"
setupRust()
setupRustIOS()
setupBrewPackages()
dir('libindy') {
echo 'iOS Test: build libindy pod'
sh './build-libindy-ios.sh x86_64-apple-ios'
}
dir('wrappers/ios/libindy-pod') {
echo "iOS Test: Installing dependencies (pods)"
withEnv([
"GEM_PATH=$HOME/.gem.indy_sdk",
"GEM_HOME=$HOME/.gem.indy_sdk"
]) {
sh "pod install --repo-update"
}
}
// FIXME replace this hack (manually rewrite installed pod)
sh "rm -f wrappers/ios/libindy-pod/Pods/libindy/*.[ah]"
sh "cp libindy/out_libindy_pod/*.[ah] wrappers/ios/libindy-pod/Pods/libindy"
dir('wrappers/ios/libindy-pod') {
echo "iOS Test: Testing"
sh "xcodebuild test -workspace Indy.xcworkspace -scheme Indy-demo -destination 'platform=iOS Simulator,name=iPhone X IndySDK,OS=11.2'"
}
} finally {
try {
sh "docker stop indy_pool"
} catch (ignore) {
}
try {
sh "docker rm indy_pool"
} catch (ignore) {
}
step([$class: 'WsCleanup'])
}
}
}
}
def ubuntuTesting() {
node('ubuntu') {
stage('Ubuntu Test') {
linuxTesting("ci/ubuntu.dockerfile ci", "Ubuntu", "pool_network")
}
}
}
def rhelTesting() {
node('ubuntu') {
stage('RedHat Test') {
linuxTesting("ci/amazon.dockerfile ci", "RedHat", "pool_network")
}
}
}
def linuxTesting(file, env_name, network_name) {
def poolInst
try {
echo "${env_name} Test: Checkout csm"
checkout scm
poolInst = openPool(env_name, network_name)
def testEnv
def additionalFeatures = "sodium_static"
dir('libindy') {
echo "${env_name} Libindy Test: Build docker image"
testEnv = dockerBuild('libindy', file)
testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") {
echo "${env_name} Libindy Test: Build"
sh "cargo build --features \"fatal_warnings $additionalFeatures\""
}
}
sh "cp libindy/target/debug/libindy.so wrappers/java/lib"
sh "cp libindy/target/debug/libindy.so wrappers/python"
sh "cp libindy/target/debug/libindy.so wrappers/nodejs"
sh "cp libindy/target/debug/libindy.so cli"
sh "cp libindy/target/debug/libindy.so libnullpay"
dir('libnullpay') {
echo "${env_name} Libnullpay Test: Build docker image"
testEnv.inside("--ip=\"10.0.0.3\" --network=${network_name}") {
echo "${env_name} Libnullpay Test: Build"
sh "LIBRARY_PATH=./ cargo build --features fatal_warnings"
}
}
sh "cp libnullpay/target/debug/libnullpay.so cli"
stash includes: 'wrappers/java/lib/libindy.so', name: "LibindyJavaSO${env_name}"
stash includes: 'wrappers/python/libindy.so', name: "LibindyPythonSO${env_name}"
stash includes: 'wrappers/nodejs/libindy.so', name: "LibindyNodejsSO${env_name}"
stash includes: 'cli/libindy.so', name: "LibindyCliSO${env_name}"
stash includes: 'cli/libnullpay.so', name: "LibnullpayCliSO${env_name}"
parallel([
"${env_name}-libindy-test": {
dir('libindy') {
testEnv.inside("--network=${network_name}") {
echo "${env_name} Libindy Test: Test"
echo "${env_name} Libindy Test: Build Test"
sh "RUST_BACKTRACE=1 cargo test --no-run --features $additionalFeatures"
echo "${env_name} Libindy Test: Run tests"
sh "RUST_BACKTRACE=1 RUST_LOG=indy::=debug,zmq=trace RUST_TEST_THREADS=1 TEST_POOL_IP=10.0.0.2 cargo test --features $additionalFeatures"
}
}
},
"${env_name}-libnullpay-test": {
dir('libnullpay') {
testEnv.inside("--network=${network_name}") {
echo "${env_name} Libnullpay Test: Test"
echo "${env_name} Libnullpay Test: Build Test"
sh "LIBRARY_PATH=./ RUST_BACKTRACE=1 cargo test --no-run"
echo "${env_name} Libnullpay Test: Run tests"
sh 'LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} RUST_BACKTRACE=1 RUST_LOG=indy::=debug,zmq=trace RUST_TEST_THREADS=1 TEST_POOL_IP=10.0.0.2 cargo test'
}
}
},
"${env_name}-java-test" : { linuxModuleTesting(file, env_name, network_name, this.&linuxJavaTesting) },
"${env_name}-python-test" : { linuxModuleTesting(file, env_name, network_name, this.&linuxPythonTesting) },
"${env_name}-nodejs-test" : { linuxModuleTesting(file, env_name, network_name, this.&linuxNodejsTesting) },
"${env_name}-cli-test" : { linuxModuleTesting(file, env_name, network_name, this.&linuxCLITesting) }
])
}
finally {
closePool(env_name, network_name, poolInst)
}
}
def linuxModuleTesting(file, env_name, network_name, module_tester) {
node('ubuntu') {
def poolInst
try {
echo "${env_name} Test: Checkout csm"
checkout scm
poolInst = openPool(env_name, network_name)
def testEnv
dir('libindy') {
echo "${env_name} Libindy Test: Build docker image"
testEnv = dockerBuild('libindy', file)
}
module_tester(env_name, network_name, testEnv)
} finally {
closePool(env_name, network_name, poolInst)
}
}
}
def linuxJavaTesting(env_name, network_name, testEnv) {
unstash name: "LibindyJavaSO${env_name}"
dir('wrappers/java') {
testEnv.inside("--network=${network_name}") {
echo "${env_name} Libindy Test: Test java wrapper"
sh "RUST_LOG=indy::=debug,zmq=trace TEST_POOL_IP=10.0.0.2 mvn clean test"
}
}
}
def linuxPythonTesting(env_name, network_name, testEnv) {
unstash name: "LibindyPythonSO${env_name}"
dir('wrappers/python') {
testEnv.inside("--network=${network_name}") {
echo "${env_name} Libindy Test: Test python wrapper"
sh '''
python3.5 -m pip install --user -e .
LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} RUST_LOG=indy::=debug,zmq=trace TEST_POOL_IP=10.0.0.2 python3.5 -m pytest
'''
}
}
}
def linuxNodejsTesting(env_name, network_name, testEnv) {
unstash name: "LibindyNodejsSO${env_name}"
testEnv.inside("--network=${network_name}") {
echo "${env_name} Libindy Test: Test nodejs wrapper"
sh '''
cd wrappers/nodejs
npm run prepare
npm install
LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} RUST_LOG=trace TEST_POOL_IP=10.0.0.2 npm test
'''
}
}
def linuxCLITesting(env_name, network_name, testEnv) {
unstash name: "LibindyCliSO${env_name}"
unstash name: "LibnullpayCliSO${env_name}"
dir('cli') {
testEnv.inside("--network=${network_name}") {
echo "${env_name} Indy Cli Test: Build"
sh 'LIBRARY_PATH=./ RUST_BACKTRACE=1 cargo test --features "nullpay_plugin" --no-run'
echo "${env_name} Indy Cli Test: Run tests"
sh 'LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} RUST_BACKTRACE=1 RUST_LOG=indy::=debug,zmq=trace RUST_TEST_THREADS=1 TEST_POOL_IP=10.0.0.2 cargo test --features "nullpay_plugin"'
}
}
}
def getBuildPoolVerOptions(pool_type, plenum_ver, anoncreds_ver, node_ver) {
if (pool_type != null && plenum_ver != null && anoncreds_ver != null && node_ver != null) {
return "--build-arg=indy_stream=${pool_type} --build-arg indy_plenum_ver=${plenum_ver} --build-arg indy_anoncreds_ver=${anoncreds_ver} --build-arg indy_node_ver=${node_ver}"
} else {
return ""
}
}
def getUserUid() {
return sh(returnStdout: true, script: 'id -u').trim()
}
def dockerBuild(name, file = 'ci/ubuntu.dockerfile ci', customParams = '') {
return docker.build("$name-test", "--build-arg uid=${getUserUid()} ${customParams} -f $file")
}
def dockerClean(env_name, network_name) {
try {
try {
sh "docker ps --format '{{.ID}}' --filter network=${network_name} | xargs docker rm -f || true" //TODO: FIXME
} catch (error) {
echo "${env_name} Test: error while force clean-up network ${network_name} - ${error}"
}
try {
echo "${env_name} Test: remove pool network ${network_name}"
sh "docker network rm ${network_name} || true" //TODO: FIXME
} catch (error) {
echo "${env_name} Test: error while delete ${network_name} - ${error}"
}
}
finally {
sh "docker container prune -f"
sh "docker network prune -f"
}
}
def openPool(env_name, network_name, pool_type = null, pool_ver = null, plenum_ver = null, anoncreds_ver = null, node_ver = null) {
echo "${env_name} Test: Clean docker"
dockerClean(env_name, network_name)
echo "${env_name} Test: Create docker network (${network_name}) for nodes pool and test image"
sh "docker network create --subnet=10.0.0.0/8 ${network_name}"
echo "${env_name} Test: Build docker image for nodes pool ver. ${pool_ver}"
echo "${env_name} Test: Building nodes pool for versions: plenum ${plenum_ver}, anoncreds ${anoncreds_ver}, node ${node_ver}"
verOptions = getBuildPoolVerOptions(pool_type, plenum_ver, anoncreds_ver, node_ver)
def poolEnv = dockerBuild("indy_pool_${pool_ver}", 'ci/indy-pool.dockerfile ci', "--build-arg pool_ip=10.0.0.2 ${verOptions}")
echo "${env_name} Test: Run nodes pool"
return poolEnv.run("--ip=\"10.0.0.2\" --network=${network_name}")
}
def closePool(env_name, network_name, poolInst) {
echo "${env_name} Test: Cleanup"
try {
echo "${env_name} Test: stop pool"
poolInst.stop()
} catch (error) {
echo "${env_name} Tests: error while stop pool ${error}"
}
finally {
dockerClean(env_name, network_name)
}
step([$class: 'WsCleanup'])
}
def setupRust() {
sh "rustup default 1.26.0"
}
def setupRustIOS() {
sh "rustup target add x86_64-apple-ios"
}
def setupBrewPackages() {
sh "brew switch libsodium 1.0.12"
sh "brew switch openssl 1.0.2l"
sh "brew switch zeromq 4.2.3"
}