Commit bf1037d4 authored by Michael Pöhn's avatar Michael Pöhn

implemented stretch bootstrapping for virtualbox

parent 83e93696
......@@ -94,7 +94,7 @@ def init_params(provider, debver, workdir='.'):
'python-minimal',
'python2.7',
'python2.7-minimal')
if debver == 'jessie':
if debver == 'jessie64':
params['deb_packages'] += ('perl-modules',)
if provider == 'libvirt':
......@@ -107,18 +107,20 @@ def init_params(provider, debver, workdir='.'):
params['img_path_vmdk'] = os.path.join(workdir,
params['img_name_vmdk'])
params['ovf_path'] = os.path.join(workdir, 'box.ovf')
if debver == 'jessie':
if debver == 'jessie64':
params['deb_packages'] += ('virtualbox-guest-dkms',
'virtualbox-guest-utils',
'linux-headers-amd64')
return params
def write_bootstrap_script(path, deb_mirror, deb_distro, username):
def write_bootstrap_script(path, deb_mirror, deb_distro, username, provider):
with open(path, 'w') as f:
f.write(get_resource_as_string('debootstrap-custom.sh')
.format(username=username,
deb_mirror=deb_mirror,
deb_distro=deb_distro))
deb_distro=deb_distro,
provider=provider))
st = os.stat(path)
os.chmod(path, st.st_mode |
stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
......@@ -129,10 +131,10 @@ def exec_vmdebootstrap(params, provider, verbose=False, dry_run=False):
write_bootstrap_script(params['boostrapscript'],
params['deb_mirror'],
params['deb_distro'],
params['username'])
params['username'],
provider)
cmd = [shutil.which('vmdebootstrap'),
'--verbose' if verbose else None,
'--grub',
'--image={}'.format(params['img_path_raw']),
'--size={}'.format(params['size']),
......@@ -147,7 +149,8 @@ def exec_vmdebootstrap(params, provider, verbose=False, dry_run=False):
'--systemd-network',
'--sudo',
'--sparse']
cmd = [x for x in cmd if x is not None] # strip nones
if verbose:
cmd += ['--verbose']
if provider == 'virtualbox':
cmd += ['--debootstrapopts=components=main,contrib']
if dry_run:
......@@ -167,6 +170,10 @@ def libvirt_convert_raw_to_qcow2(params, verbose=False, dry_run=False):
params['img_path_qcow2'])
logging.debug('> {}'.format(' '.join(cmd)))
if not dry_run:
if os.path.isfile(params['img_path_qcow2']):
os.remove(params['img_path_qcow2'])
logging.debug('removed already existing file: {}'.format(
params['img_path_qcow2']))
logging.info('converting raw image to qcow2 ...')
subprocess.call(cmd)
else:
......@@ -233,6 +240,10 @@ def vbox_convert_raw_to_vmdk(params, dry_run=False):
'VMDK')
logging.debug('> {}'.format(' '.join(cmd)))
if not dry_run:
if os.path.isfile(params['img_path_vmdk']):
os.remove(params['img_path_vmdk'])
logging.debug('removed already existing file: {}'.format(
params['img_path_vmdk']))
logging.info('converting raw image to vmdk ...')
subprocess.call(cmd)
else:
......@@ -315,9 +326,14 @@ def main(provider='virtualbox', debver='jessie64',
"(Please install virtualbox.)")
elif provider == 'libvirt':
if not shutil.which('qemu-img'):
raise BaseboxException("Can not fine 'qemu-img' executable. "
raise BaseboxException("Can not find 'qemu-img' executable. "
"(Please install qemu-utils.)")
if provider == 'virtualbox' and debver == 'stretch64':
if not shutil.which('systemd-nspawn'):
raise BaseboxException("Can not find 'systemd-nspawn' executable. "
"(Please install systemd-container.)")
with tempfile.TemporaryDirectory() as tmpdir:
if options.workdir:
......
......@@ -2,6 +2,7 @@
set -e
VMROOT=$1
PROVIDER="{provider}"
DEB_DISTRO="{deb_distro}"
USERNAME="{username}"
USERHOME="$VMROOT/home/$USERNAME"
......@@ -16,9 +17,21 @@ echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4
chmod 600 $USERHOME/.ssh/authorized_keys
chown $VGRNT_UID:$VGRNT_GID $USERHOME/.ssh/authorized_keys
if [ $DEB_DISTRO = 'stretch' ]; then
echo 'deb http://download.virtualbox.org/virtualbox/debian stretch contrib' > $VMROOT/etc/apt/sources.list.d/virtualbox.list
echo 'deb https://deb.debian.org/debian stretch-backports main contrib' > $VMROOT/etc/apt/sources.list.d/stretch-backports.list
elif [ $DEB_DISTRO = 'jessie' ]; then
echo 'deb https://deb.debian.org/debian jessie-backports main contrib' > $VMROOT/etc/apt/sources.list.d/jessie-backports.list
echo 'deb http://deb.debian.org/debian stretch-backports main contrib' > $VMROOT/etc/apt/sources.list.d/stretch-backports.list
if [ $PROVIDER = 'virtualbox' ]; then
# hack dns settings
systemd-nspawn -D $VMROOT /usr/bin/unlink /etc/resolv.conf
systemd-nspawn -D $VMROOT /bin/bash -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf'
systemd-nspawn -D $VMROOT /usr/bin/apt-get update -y
systemd-nspawn -D $VMROOT /usr/bin/apt-get install -y virtualbox-guest-dkms virtualbox-guest-utils linux-headers-amd64
# restore hacked dns settings
systemd-nspawn -D $VMROOT /bin/bash -c 'unlink /etc/resolv.conf && ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf'
fi
fi
Vagrant.configure("2") do |config|
config.vm.box = "fdroid-stretch64"
#config.vm.box = "fdroid-jessie64"
config.vm.provider :libvirt do |libvirt|
libvirt.driver = "kvm"
......
Vagrant.configure("2") do |config|
config.vm.box = "fdroid-stretch64"
config.vm.box = "fdroid-jessie64"
#config.vm.box = "fdroid-stretch64"
end
......@@ -34,7 +34,8 @@ class MkBsBoxTest(unittest.TestCase):
with tempfile.TemporaryDirectory() as tmpdir:
path = os.path.join(tmpdir, 'script.sh')
makebuildserver_basebox.write_bootstrap_script(
path, 'http://deb.debian.org/debian', 'jessie', 'theUsersName')
path, 'http://deb.debian.org/debian', 'jessie',
'theUsersName', 'libvirt')
self.assertTrue(os.path.isfile(path))
self.assertTrue(os.access(path, os.X_OK))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment