forked from hyperledger-archives/indy-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.ci
383 lines (324 loc) · 13.5 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
#!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 test --no-run"
echo "Windows Libindy Test: Run tests"
withEnv([
"RUST_TEST_THREADS=1",
"RUST_LOG=indy::,zmq=trace",
"TEST_POOL_IP=$INDY_SDK_SERVER_IP"
]) {
bat "cargo test"
}
}
}
dir('cli') {
bat "sed -i -e \"s/10\\.0\\.0\\.2/${INDY_SDK_SERVER_IP}/g\" docker_pool_transactions_genesis"
bat "copy $WORKSPACE\\libindy\\target\\debug\\indy.dll $WORKSPACE\\libindy\\prebuilt\\lib"
bat "copy $WORKSPACE\\libindy\\target\\debug\\indy.lib $WORKSPACE\\libindy\\prebuilt\\lib"
echo "Windows Indy Cli Test: Build"
withEnv([
"INDY_DIR=$WORKSPACE\\libindy\\prebuilt",
"RUST_BACKTRACE=1"
]) {
bat "cargo test --no-run"
echo "Windows Indy Cli Test: Run tests"
withEnv([
"RUST_TEST_THREADS=1",
"RUST_LOG=indy::,zmq=trace",
"TEST_POOL_IP=$INDY_SDK_SERVER_IP"
]) {
bat "cargo test"
}
}
}
//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"
// 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)"
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
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"
}
}
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 cli"
stash includes: 'wrappers/java/lib/libindy.so', name: "LibindyJavaSO${env_name}"
stash includes: 'wrappers/python/libindy.so', name: "LibindyPythonSO${env_name}"
stash includes: 'cli/libindy.so', name: "LibindyCliSO${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"
echo "${env_name} Libindy Test: Run tests"
sh "RUST_BACKTRACE=1 RUST_LOG=indy::,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}-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::,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::,zmq=trace TEST_POOL_IP=10.0.0.2 python3.5 -m pytest
'''
}
}
}
def linuxCLITesting(env_name, network_name, testEnv) {
unstash name: "LibindyCliSO${env_name}"
dir('cli') {
testEnv.inside("--network=${network_name}") {
echo "${env_name} Indy Cli Test: Build"
sh "LIBRARY_PATH=./ RUST_BACKTRACE=1 cargo test --no-run"
echo "${env_name} Indy Cli Test: Run tests"
sh 'LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} RUST_BACKTRACE=1 RUST_LOG=indy::,zmq=trace RUST_TEST_THREADS=1 TEST_POOL_IP=10.0.0.2 cargo test'
}
}
}
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.25.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"
}