import subprocess
import time
import hashlib
+import yaml
from clint.textui import progress
from optparse import OptionParser
'cachedir': cachedir,
'cpus': 1,
'memory': 1024,
+ 'hwvirtex': 'off',
}
# load config file, if present
if not os.path.exists(cachedir):
os.makedirs(cachedir, 0o755)
+if config['apt_package_cache']:
+ config['aptcachedir'] = cachedir + '/apt/archives'
+
cachefiles = [
('https://dl.google.com/android/repository/tools_r25.1.7-linux.zip',
'3ca053600a86a5a64d5571edfbb1dad27f2bda3bfd2d38e2fe54322610b1ef0b'),
print("Invalid shasum of '" + v + "' detected for " + local_filename)
sys.exit(1)
-# allow specifying a list/tuple that includes cached local copy
-if type(config['baseboxurl']) in (list, tuple) or config['baseboxurl'][0] in ('(', '['):
- baseboxurl = config['baseboxurl']
-else:
- baseboxurl = '"{0}"'.format(config['baseboxurl'])
-
# use VirtualBox software virtualization if hardware is not available,
# like if this is being run in kvm or some other VM platform, like
# http://jenkins.debian.net, the values are 'on' or 'off'
-hwvirtex = 'off'
if sys.platform.startswith('darwin'):
# all < 10 year old Macs work, and OSX servers as VM host are very
# rare, but this could also be auto-detected if someone codes it
- hwvirtex = 'on'
+ config['hwvirtex'] = 'on'
elif os.path.exists('/proc/cpuinfo'):
with open('/proc/cpuinfo') as f:
contents = f.read()
if 'vmx' in contents or 'svm' in contents:
- hwvirtex = 'on'
+ config['hwvirtex'] = 'on'
+
+del(config['__builtins__']) # added by compile/exec
+with open(os.path.join(serverdir, 'Vagrantfile.yaml'), 'w') as f:
+ yaml.dump(config, f)
# Generate an appropriate Vagrantfile for the buildserver, based on our
# settings...
vagrantfile = """
+require 'yaml'
+configfile = YAML.load_file('Vagrantfile.yaml')
+
Vagrant.configure("2") do |config|
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.enable :chef
end
- config.vm.box = "{0}"
- config.vm.box_url = {1}
+ config.vm.box = configfile['basebox']
+ config.vm.box_url = configfile['baseboxurl']
config.vm.provider "virtualbox" do |v|
- v.customize ["modifyvm", :id, "--memory", "{2}"]
- v.customize ["modifyvm", :id, "--cpus", "{3}"]
- v.customize ["modifyvm", :id, "--hwvirtex", "{4}"]
+ v.customize ["modifyvm", :id, "--memory", configfile['memory']]
+ v.customize ["modifyvm", :id, "--cpus", configfile['cpus']]
+ v.customize ["modifyvm", :id, "--hwvirtex", configfile['hwvirtex']]
end
- config.vm.boot_timeout = {5}
+ config.vm.boot_timeout = configfile['boot_timeout']
config.vm.provision :shell, :path => "fixpaths.sh"
-""".format(config['basebox'],
- baseboxurl,
- config['memory'],
- config.get('cpus', 1),
- hwvirtex,
- config['boot_timeout'])
-if 'aptproxy' in config and config['aptproxy']:
- vagrantfile += """
- config.vm.provision :shell, :inline => 'sudo echo "Acquire::http {{ Proxy \\"{0}\\"; }};" > /etc/apt/apt.conf.d/02proxy && sudo apt-get update'
-""".format(config['aptproxy'])
-
-# buildserver/ is shared to the VM's /vagrant by default so the old default
-# does not need a custom mount
-if cachedir != 'buildserver/cache':
- vagrantfile += """
- config.vm.synced_folder '{0}', '/vagrant/cache',
- owner: 'root', group: 'root', create: true
-""".format(cachedir)
-
-# cache .deb packages on the host via a mount trick
-if config['apt_package_cache']:
- aptcachedir = cachedir + '/apt/archives'
- vagrantfile += """
- config.vm.synced_folder "{0}", "/var/cache/apt/archives",
- owner: 'root', group: 'root', create: true
-""".format(aptcachedir)
-vagrantfile += """
+ if configfile.has_key? "aptproxy"
+ config.vm.provision :shell, path: "provision-apt-proxy",
+ args: [configfile["aptproxy"]]
+ end
+
+ # buildserver/ is shared to the VM's /vagrant by default so the old
+ # default does not need a custom mount
+ if configfile["cachedir"] != "buildserver/cache"
+ config.vm.synced_folder configfile["cachedir"], '/vagrant/cache',
+ owner: 'root', group: 'root', create: true
+ end
+
+ # cache .deb packages on the host via a mount trick
+ if configfile.has_key? "aptcachedir"
+ config.vm.synced_folder configfile["aptcachedir"], "/var/cache/apt/archives",
+ owner: 'root', group: 'root', create: true
+ end
config.vm.provision "shell", path: "setup-env-vars",
args: ["/home/vagrant/android-sdk"]
config.vm.provision "shell", path: "provision-apt-get-install",
- args: ["{0}"]
+ args: [configfile['debian_mirror']]
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
end
end
-""".format(config['debian_mirror'])
+"""
# Check against the existing Vagrantfile, and if they differ, we need to