mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-04 22:40:12 +01:00
buildserver: auto-detect and use libvirt's QEMU+KVM
For running in QEMU/KVM guests like on jenkins.debian.net, this sets up the whole process automatically. This only really covers the case where this is running in a KVM guest, and the original case of running VirtualBox on bare metal. It could be extended to cover more cases if someone wanted to.
This commit is contained in:
parent
f306e32636
commit
68ec7c2e88
@ -48,3 +48,11 @@
|
||||
# about the timeout, extend the timeout here. (default: 600 seconds)
|
||||
#
|
||||
# boot_timeout = 1200
|
||||
|
||||
# By default, this whole process uses VirtualBox as the provider, but
|
||||
# QEMU+KVM is also supported via the libvirt plugin to vagrant. If
|
||||
# this is run within a KVM guest, then libvirt's QEMU+KVM will be used
|
||||
# automatically. It can also be manually enabled by uncommenting
|
||||
# below:
|
||||
#
|
||||
# vm_provider = 'libvirt'
|
||||
|
@ -64,8 +64,20 @@ config = {
|
||||
'cpus': 1,
|
||||
'memory': 1024,
|
||||
'hwvirtex': 'off',
|
||||
'vm_provider': 'virtualbox',
|
||||
}
|
||||
|
||||
if os.path.isfile('/usr/bin/systemd-detect-virt'):
|
||||
try:
|
||||
virt = subprocess.check_output('/usr/bin/systemd-detect-virt').strip().decode('utf-8')
|
||||
except subprocess.CalledProcessError as e:
|
||||
virt = 'none'
|
||||
if virt == 'qemu' or virt == 'kvm':
|
||||
print('Running in a VM guest, defaulting to QEMU/KVM via libvirt')
|
||||
config['vm_provider'] = 'libvirt'
|
||||
elif virt != 'none':
|
||||
print('Running in an unsupported VM guest (' + virt + ')!')
|
||||
|
||||
# load config file, if present
|
||||
if os.path.exists('makebuildserver.config.py'):
|
||||
exec(compile(open('makebuildserver.config.py').read(), 'makebuildserver.config.py', 'exec'), config)
|
||||
@ -346,6 +358,7 @@ elif os.path.exists('/proc/cpuinfo'):
|
||||
vf = os.path.join(serverdir, 'Vagrantfile.yaml')
|
||||
writevf = True
|
||||
if os.path.exists(vf):
|
||||
print('Halting', serverdir)
|
||||
vagrant(['halt'], serverdir)
|
||||
with open(vf, 'r', encoding='utf-8') as f:
|
||||
oldconfig = yaml.load(f)
|
||||
@ -361,6 +374,33 @@ if writevf:
|
||||
with open(vf, 'w', encoding='utf-8') as f:
|
||||
yaml.dump(config, f)
|
||||
|
||||
if config['vm_provider'] == 'libvirt':
|
||||
returncode, out = vagrant(['box', 'list'], serverdir, printout=options.verbose)
|
||||
found_basebox = False
|
||||
needs_mutate = False
|
||||
for line in out.splitlines():
|
||||
if line.startswith(config['basebox']):
|
||||
found_basebox = True
|
||||
if line.split('(')[1].split(',')[0] != 'libvirt':
|
||||
needs_mutate = True
|
||||
continue
|
||||
if not found_basebox:
|
||||
if isinstance(config['baseboxurl'], str):
|
||||
baseboxurl = config['baseboxurl']
|
||||
else:
|
||||
baseboxurl = config['baseboxurl'][0]
|
||||
print('Adding', config['basebox'], 'from', baseboxurl)
|
||||
vagrant(['box', 'add', '--name', config['basebox'], baseboxurl],
|
||||
serverdir, printout=options.verbose)
|
||||
needs_mutate = True
|
||||
if needs_mutate:
|
||||
print('Converting', config['basebox'], 'to libvirt format')
|
||||
vagrant(['mutate', config['basebox'], 'libvirt'],
|
||||
serverdir, printout=options.verbose)
|
||||
print('Removing virtualbox format copy of', config['basebox'])
|
||||
vagrant(['box', 'remove', '--provider', 'virtualbox', config['basebox']],
|
||||
serverdir, printout=options.verbose)
|
||||
|
||||
print("Configuring build server VM")
|
||||
returncode, out = vagrant(['up', '--provision'], serverdir, printout=True)
|
||||
with open(os.path.join(serverdir, 'up.log'), 'w') as log:
|
||||
|
Loading…
Reference in New Issue
Block a user