mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-05 18:50:09 +02:00
buildserver: move code into main() method to always stop thread
By running the whole program in a main() function, it can be wrapped in try/finally in order to stop the background display thread. This is also done in ./fdroid, its standard practice for Python CLI utilities.
This commit is contained in:
parent
675500ad88
commit
6464ec55b7
@ -20,7 +20,7 @@ if not os.path.exists('makebuildserver') and not os.path.exists('buildserver'):
|
|||||||
|
|
||||||
|
|
||||||
boxfile = os.path.join(os.getcwd(), 'buildserver.box')
|
boxfile = os.path.join(os.getcwd(), 'buildserver.box')
|
||||||
serverdir = 'buildserver'
|
tail = None
|
||||||
|
|
||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
||||||
@ -293,7 +293,10 @@ def sha256_for_file(path):
|
|||||||
return s.hexdigest()
|
return s.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
for srcurl, shasum in cachefiles:
|
def main():
|
||||||
|
global cachedir, cachefiles, config, tail
|
||||||
|
|
||||||
|
for srcurl, shasum in cachefiles:
|
||||||
filename = os.path.basename(srcurl)
|
filename = os.path.basename(srcurl)
|
||||||
local_filename = os.path.join(cachedir, filename)
|
local_filename = os.path.join(cachedir, filename)
|
||||||
|
|
||||||
@ -345,44 +348,45 @@ for srcurl, shasum in cachefiles:
|
|||||||
os.remove(local_filename)
|
os.remove(local_filename)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
local_qt_filename = os.path.join(cachedir, 'qt-opensource-linux-x64-android-5.7.0.run')
|
local_qt_filename = os.path.join(cachedir, 'qt-opensource-linux-x64-android-5.7.0.run')
|
||||||
print("Setting executable bit for " + local_qt_filename)
|
print("Setting executable bit for " + local_qt_filename)
|
||||||
os.chmod(local_qt_filename, 0o755)
|
os.chmod(local_qt_filename, 0o755)
|
||||||
|
|
||||||
# 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'
|
||||||
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
|
||||||
config['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:
|
||||||
config['hwvirtex'] = 'on'
|
config['hwvirtex'] = 'on'
|
||||||
|
|
||||||
logfilename = os.path.join(serverdir, 'up.log')
|
serverdir = os.path.join(os.getcwd(), 'buildserver')
|
||||||
if not os.path.exists(logfilename):
|
logfilename = os.path.join(serverdir, 'up.log')
|
||||||
|
if not os.path.exists(logfilename):
|
||||||
open(logfilename, 'a').close() # create blank file
|
open(logfilename, 'a').close() # create blank file
|
||||||
log_cm = vagrant.make_file_cm(logfilename)
|
log_cm = vagrant.make_file_cm(logfilename)
|
||||||
v = vagrant.Vagrant(root=serverdir, out_cm=log_cm, err_cm=log_cm)
|
v = vagrant.Vagrant(root=serverdir, out_cm=log_cm, err_cm=log_cm)
|
||||||
|
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
tail = fdroidserver.tail.Tail(logfilename)
|
tail = fdroidserver.tail.Tail(logfilename)
|
||||||
tail.start()
|
tail.start()
|
||||||
|
|
||||||
if options.clean:
|
if options.clean:
|
||||||
v.destroy()
|
v.destroy()
|
||||||
if config['vm_provider'] == 'libvirt':
|
if config['vm_provider'] == 'libvirt':
|
||||||
subprocess.call(['virsh', 'undefine', 'buildserver_default'])
|
subprocess.call(['virsh', 'undefine', 'buildserver_default'])
|
||||||
subprocess.call(['virsh', 'vol-delete', '/var/lib/libvirt/images/buildserver_default.img'])
|
subprocess.call(['virsh', 'vol-delete', '/var/lib/libvirt/images/buildserver_default.img'])
|
||||||
|
|
||||||
# Check against the existing Vagrantfile.yaml, and if they differ, we
|
# Check against the existing Vagrantfile.yaml, and if they differ, we
|
||||||
# need to create a new box:
|
# need to create a new box:
|
||||||
vf = os.path.join(serverdir, 'Vagrantfile.yaml')
|
vf = os.path.join(serverdir, 'Vagrantfile.yaml')
|
||||||
writevf = True
|
writevf = True
|
||||||
if os.path.exists(vf):
|
if os.path.exists(vf):
|
||||||
print('Halting', serverdir)
|
print('Halting', serverdir)
|
||||||
v.halt()
|
v.halt()
|
||||||
with open(vf, 'r', encoding='utf-8') as f:
|
with open(vf, 'r', encoding='utf-8') as f:
|
||||||
@ -393,13 +397,13 @@ if os.path.exists(vf):
|
|||||||
else:
|
else:
|
||||||
print("Re-provisioning existing server")
|
print("Re-provisioning existing server")
|
||||||
writevf = False
|
writevf = False
|
||||||
else:
|
else:
|
||||||
print("No existing server - building from scratch")
|
print("No existing server - building from scratch")
|
||||||
if writevf:
|
if writevf:
|
||||||
with open(vf, 'w', encoding='utf-8') as f:
|
with open(vf, 'w', encoding='utf-8') as f:
|
||||||
yaml.dump(config, f)
|
yaml.dump(config, f)
|
||||||
|
|
||||||
if config['vm_provider'] == 'libvirt':
|
if config['vm_provider'] == 'libvirt':
|
||||||
found_basebox = False
|
found_basebox = False
|
||||||
needs_mutate = False
|
needs_mutate = False
|
||||||
for box in v.box_list():
|
for box in v.box_list():
|
||||||
@ -422,29 +426,34 @@ if config['vm_provider'] == 'libvirt':
|
|||||||
print('Removing virtualbox format copy of', config['basebox'])
|
print('Removing virtualbox format copy of', config['basebox'])
|
||||||
v.box_remove(config['basebox'], 'virtualbox')
|
v.box_remove(config['basebox'], 'virtualbox')
|
||||||
|
|
||||||
print("Configuring build server VM")
|
print("Configuring build server VM")
|
||||||
v.up(provision=True)
|
v.up(provision=True)
|
||||||
|
|
||||||
print("Writing buildserver ID")
|
print("Writing buildserver ID")
|
||||||
p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE,
|
p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
buildserverid = p.communicate()[0].strip()
|
buildserverid = p.communicate()[0].strip()
|
||||||
print("...ID is " + buildserverid)
|
print("...ID is " + buildserverid)
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
['vagrant', 'ssh', '-c', 'sh -c "echo {0} >/home/vagrant/buildserverid"'
|
['vagrant', 'ssh', '-c', 'sh -c "echo {0} >/home/vagrant/buildserverid"'
|
||||||
.format(buildserverid)],
|
.format(buildserverid)],
|
||||||
cwd=serverdir)
|
cwd=serverdir)
|
||||||
|
|
||||||
print("Stopping build server VM")
|
print("Stopping build server VM")
|
||||||
v.halt()
|
v.halt()
|
||||||
|
|
||||||
print("Packaging")
|
print("Packaging")
|
||||||
v.package(output=boxfile)
|
v.package(output=boxfile)
|
||||||
|
|
||||||
print("Adding box")
|
print("Adding box")
|
||||||
v.box_add('buildserver', boxfile, force=True)
|
v.box_add('buildserver', boxfile, force=True)
|
||||||
|
|
||||||
os.remove(boxfile)
|
os.remove(boxfile)
|
||||||
|
|
||||||
if tail is not None:
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
finally:
|
||||||
|
if tail is not None:
|
||||||
tail.stop()
|
tail.stop()
|
||||||
|
Loading…
Reference in New Issue
Block a user