8 execfile('makebs.config.py', globals())
10 def vagrant(params, cwd=None, printout=False):
13 :param: list of parameters to pass to vagrant
14 :cwd: directory to run in, or None for current directory
15 :printout: True to print output in realtime, False to just
17 :returns: (ret, out) where ret is the return code, and out
18 is the stdout (and stderr) from vagrant
20 p = subprocess.Popen(['vagrant'] + params, cwd=cwd,
21 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
25 line = p.stdout.readline()
32 out = p.communicate()[0]
33 return (p.returncode, out)
35 boxfile = 'buildserver.box'
36 serverdir = 'buildserver'
38 if not os.path.exists('makebuildserver.py') or not os.path.exists(serverdir):
39 print 'This must be run from the correct directory!'
42 if os.path.exists(boxfile):
46 # Update cached files.
47 cachedir = os.path.join('buildserver', 'cache')
48 if not os.path.exists(cachedir):
51 ('android-sdk_r21.0.1-linux.tgz',
52 'http://dl.google.com/android/android-sdk_r21.0.1-linux.tgz')]
55 ('android-ndk-r8e-linux-x86_64.tar.bz2',
56 'http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2')])
59 ('android-ndk-r8e-linux-x86.tar.bz2',
60 'http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86.tar.bz2')])
62 for f, src in cachefiles:
63 if not os.path.exists(os.path.join(cachedir, f)):
64 print "Downloading " + f + " to cache"
65 if subprocess.call(['wget', src], cwd=cachedir) != 0:
66 print "...download of " + f + " failed."
71 # Generate an appropriate Vagrantfile for the buildserver, based on our
74 Vagrant::Config.run do |config|
77 config.vm.box_url = "{1}"
79 config.vm.customize ["modifyvm", :id, "--memory", "{2}"]
81 config.vm.provision :shell, :path => "fixpaths.sh"
82 """.format(basebox, baseboxurl, memory)
85 config.vm.provision :shell, :inline => 'sudo echo "Acquire::http {{ Proxy \\"{0}\\"; }};" > /etc/apt/apt.conf.d/02proxy && sudo apt-get update'
88 config.vm.provision :chef_solo do |chef|
89 chef.cookbooks_path = "cookbooks"
90 chef.log_level = :debug
93 :sdk_loc => "/home/vagrant/android-sdk",
94 :ndk_loc => "/home/vagrant/android-ndk",
98 chef.add_recipe "fdroidbuild-general"
99 chef.add_recipe "android-sdk"
100 chef.add_recipe "android-ndk"
105 # Check against the existing Vagrantfile, and if they differ, we need to
107 vf = os.path.join(serverdir, 'Vagrantfile')
109 if os.path.exists(vf):
110 vagrant(['halt'], serverdir)
111 with open(vf, 'r') as f:
113 if oldvf != vagrantfile:
114 print "Server configuration has changed, rebuild from scratch is required"
115 vagrant(['destroy', '-f'], serverdir)
117 print "Re-provisioning existing server"
120 print "No existing server - building from scratch"
122 with open(vf, 'w') as f:
126 print "Configuring build server VM"
127 returncode, out = vagrant(['up'], serverdir, printout=True)
128 with open(os.path.join(serverdir, 'up.log'), 'w') as log:
131 print "Failed to configure server"
133 print "Stopping build server VM"
134 vagrant(['halt'], serverdir)
136 print "Waiting for build server VM to be finished"
140 returncode, out = vagrant(['status'], serverdir)
142 print "Error while checking status"
144 for line in out.splitlines():
145 if line.startswith("default"):
146 if line.find("poweroff") != -1:
149 print "Status: " + line
152 vagrant(['package', '--output', os.path.join('..', boxfile)], serverdir)
154 vagrant(['box', 'add', 'buildserver', boxfile, '-f'])