-
Notifications
You must be signed in to change notification settings - Fork 23
/
Jenkinsfile
95 lines (95 loc) · 4.4 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
pipeline {
agent {
node {label 'bare-metal' }
}
stages {
stage('Build') {
steps {
// Build container
sh 'echo Build shock server'
sh 'docker build --no-cache -t shock:testing .'
sh 'echo Build test client'
sh 'docker build --no-cache -t shock-test-client:testing -f test/Dockerfile .'
}
}
stage('Setup') {
steps {
// Create network
sh '''
if [ -n "`docker network ls | grep shock-test`" ] ; then
echo Network already up
else
echo Creating shock-test network
docker network create shock-test
fi
'''
// start services
sh '''
if [ -n "`docker ps | grep shock-server-mongodb`" ] ; then
echo Still up shock-server-mongodb, reusing
else
docker run -d --rm --network shock-test --name shock-server-mongodb --expose=27017 mongo mongod --dbpath /data/db
fi
'''
sh '''
if [ -n "`docker ps | grep shock-auth-db`" ] ; then
echo Still up grep shock-auth-db
else
docker run -d --rm --network shock-test \
--env MYSQL_ROOT_PASSWORD=secret \
--env MYSQL_DATABASE=TestAppUsers \
--env MYSQL_USER=authService \
--env MYSQL_PASSWORD=authServicePassword \
-v `pwd`/test/dbsetup.mysql:/tmp/dbsetup.mysql \
--name shock-auth-db mysql:5.7 \
--explicit_defaults_for_timestamp --init-file /tmp/dbsetup.mysql
fi
docker ps
docker logs shock-auth-db
cat test/dbsetup.mysql '''
sh '''
if [ -n "`docker ps | grep shock-auth-server`" ] ; then
echo Still up shock-auth-server
else
docker run -d --rm --network shock-test --name shock-auth-server \
--env MYSQL_HOST=shock-auth-db \
--env MYSQL_DATABASE=TestAppUsers \
--env MYSQL_USER=authService \
--env MYSQL_PASSWORD=authServicePassword \
--env PERL5LIB=/usr/local/apache2/cgi-bin \
mgrast/authserver:latest
fi
'''
sh '''
if [ -n "`docker ps | grep 'shock-server$'`" ] ; then
echo Found old shock server, stopping and starting new one
docker stop shock-server
fi
docker run -d --rm --network shock-test --name shock-server --expose=7445 shock:testing /go/bin/shock-server --hosts shock-server-mongodb --oauth_urls "http://shock-auth-server/cgi-bin/?action=data" --oauth_bearers oauth --api-url 'http://shock-server:7445' --write 0
docker logs shock-server
'''
}
}
stage('Test') {
steps {
// execute tests
sh 'docker run -t --rm --network shock-test shock-test-client:testing /shock-tester.sh -h http://shock-server -p 7445'
sh '''docker run -t --rm --network shock-test --env DEBUG=1 --env SHOCK_HOST="http://shock-server" --env SHOCK_PORT=7445 shock-test-client:testing \
pytest /go/src/github.com/MG-RAST/Shock/test/test_shock.py'''
}
}
}
post {
always {
// shutdown container and network
sh '''
set +e
docker stop shock-server shock-server-mongodb shock-auth-server shock-auth-db
docker rmi shock:testing shock-test-client:testing
docker network rm shock-test
set -e
echo Cleanup done
'''
}
}
}