forked from cloudant/sync-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rb
executable file
·116 lines (88 loc) · 3.35 KB
/
build.rb
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
#!/usr/bin/ruby
#
# -couch <type> couchdb1.6, couchdb2.0, cloudantSAAS, cloudantlocal - default is couchdb1.6
# -platform <platfrom> java | android default is Java
# -D* gets passed into build.
#
#
params = { :d_options => Array.new }
arg_is_value = false
prev_arg = nil
ARGV.each do |arg|
if arg.start_with?("-D")
params[:d_options].push(arg)
next
end
#process arguments into a hash
unless arg_is_value
params[arg[1,arg.length] ] = nil
$prev_arg = arg[1,arg.length]
arg_is_value = true
else
params[$prev_arg] = arg
arg_is_value = false
end
end
#apply defaults
params["platform"] = "java" unless params["platform"]
params["couch"] = "couchdb1.6" unless params["couch"]
#kill any docker container that may be running on the machine.
#we don't want to effected by another failing build
system("docker rm --force couchdb")
#launch docker
puts "Starting docker container #{$couch}"
#cloudant local current runs in a Vagrant box, rather than docker, this box is *always* running on cloudantsync001
#so we skip the docker set up commands and change the options to enable connection to cloudant local
if params["couch"] == "cloudantlocal"
#remove options that will clash with cloudant local
options_to_remove = Array.new
params[:d_options].each do |d_option|
if d_option.start_with?("-Dtest.couch.username") || d_option.start_with?("-Dtest.couch.password") || d_option.start_with?("-Dtest.couch.host") || d_option.start_with?("-Dtest.couch.port")
options_to_remove.push d_option
end
end
options_to_remove.each do |option|
params[:d_options].delete option
end
#add some -d opts to point tests at local instead
params[:d_options].push "-Dtest.couch.username=admin"
params[:d_options].push "-Dtest.couch.password=pass"
#cloudant local needs a different port on Android to Java
#android needs to use a special address which maps to
#local loopback interface for the machine it is running on
if params["platform"] == "java"
params[:d_options].push "-Dtest.couch.host=127.0.0.1"
else
params[:d_options].push "-Dtest.couch.host=10.0.2.2"
end
params[:d_options].push "-Dtest.couch.port=8081" #jenkins runs on 8080 this needs to be 8081
params[:d_options].push "-Dtest.couch.ignore.auth.headers=true"
params[:d_options].push "-Dtest.couch.ignore.compaction=true"
else
docker_port = 5984
#special case for couchdb2.0 it runs on port 15984 in the docker container rather than 5984
docker_port = 15984 if params["couch"] == "couchdb2.0"
unless system("docker run -p 5984:#{docker_port} -d -h db1.dockertest --name 'couchdb' #{params["couch"]}")
#we need to stop, we failed to run the docker container, just in case we will delete
system("docker rm --force couchdb")
exit 1
end
end
puts "Performing build"
#make gradlew executable
system("chmod a+x ./gradlew ")
#exit
#handle the differences in the platform
if params["platform"] == "java"
system("./gradlew #{params[:d_options].join(" ")} clean check integrationTest")
elsif params["platform"] == "android"
system("./gradlew -b AndroidTest/build.gradle #{params[:d_options].join(" ")} clean uploadFixtures connectedCheck")
end
#get the build exit code, will exit with this after tearing down the docker container
exitcode = $?
unless params["couch"] == "cloudantlocal"
puts "Tearing down docker container"
system("docker stop couchdb")
system("docker rm couchdb")
end
exit exitcode.to_i