mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-14 19:20:29 +03:00
Merge branch 'buildserver-qemu-kvm' into 'master'
buildserver running in qemu/kvm to support KVM on KVM jenkins.debian.net runs in QEMU/KVM instances, so in order to run the F-Droid buildserver there, it needs to work inside of a KVM guest. The best way I found to do that is to create QEMU/KVM instances via KVM's "nested" virtualization support. This collection of commits enables using QEMU/KVM as the buildserver when `./makebuildserver` detects that it is running inside of KVM. Otherwise, the old behavior is default: running in VirtualBox. I have run these tests inside of ubuntu/16.04 on bare metal, which uses VirtualBox, and ubuntu/16.04 KVM guest, which uses QEMU/KVM. It'll also run on the Guardian Project jenkins box, which is Debian/jessie. @mvdan @CiaranG @krt See merge request !168
This commit is contained in:
commit
5667d16498
8 changed files with 135 additions and 13 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import requests
|
||||
import stat
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
|
|
@ -63,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)
|
||||
|
|
@ -89,6 +102,15 @@ cachedir = config['cachedir']
|
|||
if not os.path.exists(cachedir):
|
||||
os.makedirs(cachedir, 0o755)
|
||||
|
||||
tmp = cachedir
|
||||
while tmp != '/':
|
||||
mode = os.stat(tmp).st_mode
|
||||
if not (stat.S_IXUSR & mode and stat.S_IXGRP & mode and stat.S_IXOTH & mode):
|
||||
print('ERROR:', tmp, 'will not be accessible to the VM! To fix, run:')
|
||||
print(' chmod a+X', tmp)
|
||||
sys.exit(1)
|
||||
tmp = os.path.dirname(tmp)
|
||||
|
||||
if config['apt_package_cache']:
|
||||
config['aptcachedir'] = cachedir + '/apt/archives'
|
||||
|
||||
|
|
@ -338,6 +360,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)
|
||||
|
|
@ -353,6 +376,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…
Add table
Add a link
Reference in a new issue