added makebuildserver option for keeping vagrant box

This is very useful for debugging this process, and also for people
who might want to keep a working copy of the box.
This commit is contained in:
Hans-Christoph Steiner 2017-05-22 17:29:12 +02:00
parent d180aa2658
commit 5580a685db

View file

@ -30,6 +30,8 @@ parser.add_option("-c", "--clean", action="store_true", default=False,
parser.add_option('--skip-cache-update', action="store_true", default=False, parser.add_option('--skip-cache-update', action="store_true", default=False,
help="""Skip downloading and checking cache.""" help="""Skip downloading and checking cache."""
"""This assumes that the cache is already downloaded completely.""") """This assumes that the cache is already downloaded completely.""")
parser.add_option('--keep-box-file', action="store_true", default=False,
help="""Box file will not be deleted after adding it to box storage.""")
options, args = parser.parse_args() options, args = parser.parse_args()
logger = logging.getLogger('fdroidserver-makebuildserver') logger = logging.getLogger('fdroidserver-makebuildserver')
@ -329,6 +331,14 @@ def kvm_package(boxfile):
virConnect = libvirt.open('qemu:///system') virConnect = libvirt.open('qemu:///system')
storagePool = virConnect.storagePoolLookupByName('default') storagePool = virConnect.storagePoolLookupByName('default')
if storagePool: if storagePool:
if os.path.isfile('metadata.json'):
os.remove('metadata.json')
if os.path.isfile('Vagrantfile'):
os.remove('Vagrantfile')
if os.path.isfile('box.img'):
os.remove('box.img')
vol = storagePool.storageVolLookupByName(config['domain'] + '.img') vol = storagePool.storageVolLookupByName(config['domain'] + '.img')
imagepath = vol.path() imagepath = vol.path()
# TODO use a libvirt storage pool to ensure the img file is readable # TODO use a libvirt storage pool to ensure the img file is readable
@ -356,6 +366,7 @@ def kvm_package(boxfile):
end end
end end
""" """
with open('metadata.json', 'w') as fp: with open('metadata.json', 'w') as fp:
fp.write(json.dumps(metadata)) fp.write(json.dumps(metadata))
with open('Vagrantfile', 'w') as fp: with open('Vagrantfile', 'w') as fp:
@ -364,9 +375,15 @@ end
tar.add('metadata.json') tar.add('metadata.json')
tar.add('Vagrantfile') tar.add('Vagrantfile')
tar.add('box.img') tar.add('box.img')
os.remove('metadata.json') if not options.keep_box_file:
os.remove('Vagrantfile') logger.debug('box packaging complete, removing temporary files.')
os.remove('box.img') os.remove('metadata.json')
os.remove('Vagrantfile')
os.remove('box.img')
else:
logger.warn('could not connect to storage-pool \'default\',' +
'skipping packaging buildserver box')
def run_via_vagrant_ssh(v, cmdlist): def run_via_vagrant_ssh(v, cmdlist):
@ -586,7 +603,11 @@ def main():
logger.info("Adding box") logger.info("Adding box")
v.box_add('buildserver', boxfile, force=True) v.box_add('buildserver', boxfile, force=True)
os.remove(boxfile) if not options.keep_box_file:
logger.debug('box added to vagrant, ' +
'removing generated box file \'%s\'',
boxfile)
os.remove(boxfile)
if __name__ == '__main__': if __name__ == '__main__':