7 from optparse import OptionParser
9 def vagrant(params, cwd=None, printout=False):
12 :param: list of parameters to pass to vagrant
13 :cwd: directory to run in, or None for current directory
14 :printout: True to print output in realtime, False to just
16 :returns: (ret, out) where ret is the return code, and out
17 is the stdout (and stderr) from vagrant
19 p = subprocess.Popen(['vagrant'] + params, cwd=cwd,
20 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
24 line = p.stdout.readline()
31 out = p.communicate()[0]
32 return (p.returncode, out)
34 boxfile = 'buildserver.box'
35 serverdir = 'buildserver'
37 parser = OptionParser()
38 parser.add_option("-v", "--verbose", action="store_true", default=False,
39 help="Spew out even more information than normal")
40 parser.add_option("-c", "--clean", action="store_true", default=False,
41 help="Build from scratch, rather than attempting to update the existing server")
42 options, args = parser.parse_args()
45 execfile('makebs.config.py', config)
47 if not os.path.exists('makebuildserver') or not os.path.exists(serverdir):
48 print 'This must be run from the correct directory!'
51 if os.path.exists(boxfile):
55 vagrant(['destroy', '-f'], cwd=serverdir, printout=options.verbose)
57 # Update cached files.
58 cachedir = os.path.join('buildserver', 'cache')
59 if not os.path.exists(cachedir):
62 ('android-sdk_r22.3-linux.tgz',
63 'http://dl.google.com/android/android-sdk_r22.3-linux.tgz',
64 '4077575c98075480e0156c10e48a1521e31c7952768271a206870e6813057f4f'),
65 ('gradle-1.9-bin.zip',
66 'http://services.gradle.org/distributions/gradle-1.9-bin.zip',
67 '097ddc2bcbc9da2bb08cbf6bf8079585e35ad088bafd42e8716bc96405db98e9'),
69 'http://pypi.python.org/packages/source/K/Kivy/Kivy-1.7.2.tar.gz',
70 '0485e2ef97b5086df886eb01f8303cb542183d2d71a159466f99ad6c8a1d03f1')
74 ('android-ndk-r9b-linux-x86_64.tar.bz2',
75 'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2',
76 '8956e9efeea95f49425ded8bb697013b66e162b064b0f66b5c75628f76e0f532'),
77 ('android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
78 'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
79 'de93a394f7c8f3436db44568648f87738a8d09801a52f459dcad3fc047e045a1')])
82 ('android-ndk-r9b-linux-x86.tar.bz2',
83 'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86.tar.bz2',
84 '748104b829dd12afb2fdb3044634963abb24cdb0aad3b26030abe2e9e65bfc81'),
85 ('android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
86 'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
87 '606aadf815ae28cc7b0154996247c70d609f111b14e44bcbcd6cad4c87fefb6f')])
89 for f, src, shasum in cachefiles:
90 if not os.path.exists(os.path.join(cachedir, f)):
91 print "Downloading " + f + " to cache"
92 if subprocess.call(['wget', src], cwd=cachedir) != 0:
93 print "...download of " + f + " failed."
96 p = subprocess.Popen(['shasum', '-a', '256', os.path.join(cachedir, f)],
97 stdout=subprocess.PIPE)
98 v = p.communicate()[0].split(' ')[0]
100 print "Invalid shasum of '" + v + "' detected for " + f
103 print "...shasum verified for " + f
108 # Generate an appropriate Vagrantfile for the buildserver, based on our
111 Vagrant::Config.run do |config|
113 config.vm.box = "{0}"
114 config.vm.box_url = "{1}"
116 config.vm.customize ["modifyvm", :id, "--memory", "{2}"]
118 config.vm.provision :shell, :path => "fixpaths.sh"
119 """.format(config['basebox'], config['baseboxurl'], config['memory'])
120 if 'aptproxy' in config and config['aptproxy']:
122 config.vm.provision :shell, :inline => 'sudo echo "Acquire::http {{ Proxy \\"{0}\\"; }};" > /etc/apt/apt.conf.d/02proxy && sudo apt-get update'
123 """.format(config['aptproxy'])
125 config.vm.provision :chef_solo do |chef|
126 chef.cookbooks_path = "cookbooks"
127 chef.log_level = :debug
130 :sdk_loc => "/home/vagrant/android-sdk",
131 :ndk_loc => "/home/vagrant/android-ndk",
135 chef.add_recipe "fdroidbuild-general"
136 chef.add_recipe "android-sdk"
137 chef.add_recipe "android-ndk"
138 chef.add_recipe "kivy"
143 # Check against the existing Vagrantfile, and if they differ, we need to
145 vf = os.path.join(serverdir, 'Vagrantfile')
147 if os.path.exists(vf):
148 vagrant(['halt'], serverdir)
149 with open(vf, 'r') as f:
151 if oldvf != vagrantfile:
152 print "Server configuration has changed, rebuild from scratch is required"
153 vagrant(['destroy', '-f'], serverdir)
155 print "Re-provisioning existing server"
158 print "No existing server - building from scratch"
160 with open(vf, 'w') as f:
164 print "Configuring build server VM"
165 returncode, out = vagrant(['up'], serverdir, printout=True)
166 with open(os.path.join(serverdir, 'up.log'), 'w') as log:
169 print "Failed to configure server"
172 print "Writing buildserver ID"
173 p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
174 buildserverid = p.communicate()[0].strip()
175 print "...ID is " + buildserverid
177 ['vagrant', 'ssh', '-c', 'sh -c "echo {0} >/home/vagrant/buildserverid"'
178 .format(buildserverid)],
181 print "Stopping build server VM"
182 vagrant(['halt'], serverdir)
184 print "Waiting for build server VM to be finished"
188 returncode, out = vagrant(['status'], serverdir)
190 print "Error while checking status"
192 for line in out.splitlines():
193 if line.startswith("default"):
194 if line.find("poweroff") != -1:
197 print "Status: " + line
200 vagrant(['package', '--output', os.path.join('..', boxfile)], serverdir)
202 vagrant(['box', 'add', 'buildserver', boxfile, '-f'])