1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-02 09:10:11 +02:00

buildserver: send config to vagrant via YAML file

Python can easily output dicts as YAML, and a Vagrantfile is a ruby script,
which can easily read YAML.  Going this route means that Vagrantfile can
ultimately be committed to git, and the configuration will happen all via
Python dicts output as YAML.  That makes it drastically easier to follow
the code, and to make modifications.
This commit is contained in:
Hans-Christoph Steiner 2016-07-04 20:22:00 +02:00
parent 4e787cc750
commit 2e1ec71404
3 changed files with 49 additions and 42 deletions

1
.gitignore vendored
View File

@ -19,6 +19,7 @@ tmp/
tests/repo/icons* tests/repo/icons*
# files used in manual testing # files used in manual testing
/buildserver/Vagrantfile.yaml
/config.py /config.py
/tmp/ /tmp/
/logs/ /logs/

View File

@ -0,0 +1,11 @@
#!/bin/bash
echo $0
set -e
rm -f /etc/apt/apt.conf.d/02proxy
echo "Acquire::ftp::Proxy \"$1\";" >> /etc/apt/apt.conf.d/02proxy
echo "Acquire::http::Proxy \"$1\";" >> /etc/apt/apt.conf.d/02proxy
echo "Acquire::https::Proxy \"$1\";" >> /etc/apt/apt.conf.d/02proxy
apt-get update

View File

@ -6,6 +6,7 @@ import sys
import subprocess import subprocess
import time import time
import hashlib import hashlib
import yaml
from clint.textui import progress from clint.textui import progress
from optparse import OptionParser from optparse import OptionParser
@ -61,6 +62,7 @@ config = {
'cachedir': cachedir, 'cachedir': cachedir,
'cpus': 1, 'cpus': 1,
'memory': 1024, 'memory': 1024,
'hwvirtex': 'off',
} }
# load config file, if present # load config file, if present
@ -85,6 +87,9 @@ cachedir = config['cachedir']
if not os.path.exists(cachedir): if not os.path.exists(cachedir):
os.makedirs(cachedir, 0o755) os.makedirs(cachedir, 0o755)
if config['apt_package_cache']:
config['aptcachedir'] = cachedir + '/apt/archives'
cachefiles = [ cachefiles = [
('https://dl.google.com/android/repository/tools_r25.1.7-linux.zip', ('https://dl.google.com/android/repository/tools_r25.1.7-linux.zip',
'3ca053600a86a5a64d5571edfbb1dad27f2bda3bfd2d38e2fe54322610b1ef0b'), '3ca053600a86a5a64d5571edfbb1dad27f2bda3bfd2d38e2fe54322610b1ef0b'),
@ -302,29 +307,29 @@ for srcurl, shasum in cachefiles:
print("Invalid shasum of '" + v + "' detected for " + local_filename) print("Invalid shasum of '" + v + "' detected for " + local_filename)
sys.exit(1) 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, # use VirtualBox software virtualization if hardware is not available,
# like if this is being run in kvm or some other VM platform, like # like if this is being run in kvm or some other VM platform, like
# http://jenkins.debian.net, the values are 'on' or 'off' # http://jenkins.debian.net, the values are 'on' or 'off'
hwvirtex = 'off'
if sys.platform.startswith('darwin'): if sys.platform.startswith('darwin'):
# all < 10 year old Macs work, and OSX servers as VM host are very # 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 # rare, but this could also be auto-detected if someone codes it
hwvirtex = 'on' config['hwvirtex'] = 'on'
elif os.path.exists('/proc/cpuinfo'): elif os.path.exists('/proc/cpuinfo'):
with open('/proc/cpuinfo') as f: with open('/proc/cpuinfo') as f:
contents = f.read() contents = f.read()
if 'vmx' in contents or 'svm' in contents: 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 # Generate an appropriate Vagrantfile for the buildserver, based on our
# settings... # settings...
vagrantfile = """ vagrantfile = """
require 'yaml'
configfile = YAML.load_file('Vagrantfile.yaml')
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
if Vagrant.has_plugin?("vagrant-cachier") if Vagrant.has_plugin?("vagrant-cachier")
@ -334,51 +339,41 @@ Vagrant.configure("2") do |config|
config.cache.enable :chef config.cache.enable :chef
end end
config.vm.box = "{0}" config.vm.box = configfile['basebox']
config.vm.box_url = {1} config.vm.box_url = configfile['baseboxurl']
config.vm.provider "virtualbox" do |v| config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "{2}"] v.customize ["modifyvm", :id, "--memory", configfile['memory']]
v.customize ["modifyvm", :id, "--cpus", "{3}"] v.customize ["modifyvm", :id, "--cpus", configfile['cpus']]
v.customize ["modifyvm", :id, "--hwvirtex", "{4}"] v.customize ["modifyvm", :id, "--hwvirtex", configfile['hwvirtex']]
end end
config.vm.boot_timeout = {5} config.vm.boot_timeout = configfile['boot_timeout']
config.vm.provision :shell, :path => "fixpaths.sh" 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 if configfile.has_key? "aptproxy"
# does not need a custom mount config.vm.provision :shell, path: "provision-apt-proxy",
if cachedir != 'buildserver/cache': args: [configfile["aptproxy"]]
vagrantfile += """ end
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 # buildserver/ is shared to the VM's /vagrant by default so the old
if config['apt_package_cache']: # default does not need a custom mount
aptcachedir = cachedir + '/apt/archives' if configfile["cachedir"] != "buildserver/cache"
vagrantfile += """ config.vm.synced_folder configfile["cachedir"], '/vagrant/cache',
config.vm.synced_folder "{0}", "/var/cache/apt/archives", owner: 'root', group: 'root', create: true
owner: 'root', group: 'root', create: true end
""".format(aptcachedir)
vagrantfile += """ # 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", config.vm.provision "shell", path: "setup-env-vars",
args: ["/home/vagrant/android-sdk"] args: ["/home/vagrant/android-sdk"]
config.vm.provision "shell", path: "provision-apt-get-install", config.vm.provision "shell", path: "provision-apt-get-install",
args: ["{0}"] args: [configfile['debian_mirror']]
config.vm.provision :chef_solo do |chef| config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks" chef.cookbooks_path = "cookbooks"
@ -401,7 +396,7 @@ vagrantfile += """
end end
end end
""".format(config['debian_mirror']) """
# Check against the existing Vagrantfile, and if they differ, we need to # Check against the existing Vagrantfile, and if they differ, we need to