Commit 00f48a8c authored by Michael Pöhn's avatar Michael Pöhn

added debian version target (wip: only libvirt working)

parent 5bbc2161
......@@ -30,6 +30,7 @@ from argparse import ArgumentParser
SUPPORTED_PROVIDERS = ('libvirt', 'virtualbox')
SUPPORTED_DEBVERS = ('jessie64', 'stretch64')
class BaseboxException(Exception):
......@@ -46,44 +47,31 @@ def vm_size_str_to_bytes(size):
"(Try something like: '100G')".format(ssize))
def init_params(provider, workdir='.'):
def init_params(provider, debver, workdir='.'):
"""creates dict with carefully chosen parameters for buildservers"""
params = {'vm_name': 'fdroid-jessie64',
params = {'vm_name': 'fdroid-{}'.format(debver),
'hostname': 'fdroid-buildserver',
'vm_ram': 2048,
'vm_cpu': 2,
'size': '1000G',
'deb_mirror': 'http://deb.debian.org/debian',
'deb_distro': 'jessie',
'deb_distro': debver[:-2],
'deb_packages': ['openssh-server'],
'boostrapscript': os.path.join(workdir,
'fdroidserver-customize.sh'),
'username': 'vagrant',
'password': 'vagrant',
'boxfile': 'fdroid-jessie64.box'}
'boxfile': 'fdroid-{}.box'.format(debver)}
params['size_bytes'] = vm_size_str_to_bytes(params['size'])
params['size_megs'] = math.ceil(params['size_bytes'] / (2.**20))
params['size_gigs'] = math.ceil(params['size_bytes'] / (2.**30))
params['img_name_raw'] = params['vm_name'] + '.raw'
params['img_path_raw'] = os.path.join(workdir, params['img_name_raw'])
params['vagrantfile_path'] = os.path.join(workdir, 'Vagrantfile')
if provider == 'libvirt':
params['img_name_qcow2'] = params['vm_name'] + '.qcow2'
params['img_path_qcow2'] = os.path.join(workdir,
params['img_name_qcow2'])
params['metadata_json_path'] = os.path.join(workdir, 'metadata.json')
elif provider == 'virtualbox':
params['img_name_vmdk'] = params['vm_name'] + '.vmdk'
params['img_path_vmdk'] = os.path.join(workdir,
params['img_name_vmdk'])
params['ovf_path'] = os.path.join(workdir, 'box.ovf')
params['deb_packages'] += ('virtualbox-guest-dkms',
'linux-headers-amd64')
# add some packages which are missing in makebuildserver:
# (because they have been preinstalled on jessie64.box)
params['deb_packages'] += ('perl',
'perl-modules',
'git',
'git-man',
'libcurl3-gnutls',
......@@ -105,13 +93,31 @@ def init_params(provider, workdir='.'):
'python-minimal',
'python2.7',
'python2.7-minimal')
if debver == 'jessie':
params['deb_packages'] += ('perl-modules',)
if provider == 'libvirt':
params['img_name_qcow2'] = params['vm_name'] + '.qcow2'
params['img_path_qcow2'] = os.path.join(workdir,
params['img_name_qcow2'])
params['metadata_json_path'] = os.path.join(workdir, 'metadata.json')
elif provider == 'virtualbox':
params['img_name_vmdk'] = params['vm_name'] + '.vmdk'
params['img_path_vmdk'] = os.path.join(workdir,
params['img_name_vmdk'])
params['ovf_path'] = os.path.join(workdir, 'box.ovf')
if debver == 'jessie':
params['deb_packages'] += ('virtualbox-guest-dkms',
'linux-headers-amd64')
return params
def write_bootstrap_script(path, username):
def write_bootstrap_script(path, deb_mirror, deb_distro, username):
with open(path, 'w') as f:
f.write(get_resource_as_string('debootstrap-custom.sh')
.format(username=username))
.format(username=username,
deb_mirror=deb_mirror,
deb_distro=deb_distro))
st = os.stat(path)
os.chmod(path, st.st_mode |
stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
......@@ -120,6 +126,8 @@ def write_bootstrap_script(path, username):
def exec_vmdebootstrap(params, provider, verbose=False, dry_run=False):
write_bootstrap_script(params['boostrapscript'],
params['deb_mirror'],
params['deb_distro'],
params['username'])
cmd = [shutil.which('vmdebootstrap'),
......@@ -231,7 +239,11 @@ def vbox_convert_raw_to_vmdk(params, dry_run=False):
def vbox_write_ovf(params, dry_run=False):
ovf_template = get_resource_as_string('box.ovf')
if params['deb_distro'] == 'jessie':
ovf_template = get_resource_as_string('jessie.box.ovf')
elif params['deb_distro'] == 'stretch':
ovf_template = get_resource_as_string('stretch.box.ovf')
if not dry_run:
with open(params['ovf_path'], 'w') as f:
f.write(ovf_template.format(**params))
......@@ -271,7 +283,7 @@ def vbox_package_box(params, dry_run=False):
logging.info('(dry run) Skip packaging box file.')
def main(provider='virtualbox', verbose=False, dry_run=False):
def main(provider='virtualbox', debver='jessie64', verbose=False, dry_run=False):
if not os.geteuid() == 0:
raise BaseboxException('This script requires super user privileges. '
......@@ -285,6 +297,13 @@ def main(provider='virtualbox', verbose=False, dry_run=False):
supported=providers))
logging.info("selected provider: '{}'".format(provider))
if debver not in SUPPORTED_DEBVERS:
supvers = ', '.join(SUPPORTED_DEBVERS)
raise BaseboxException("target debian version '{debver}' not "
"supported. Supported versions are: "
"{supvers}".format(debver=debver,
supvers=supvers))
if not shutil.which('vmdebootstrap'):
raise BaseboxException("Can not find 'vmdebootstrap' executable. "
"(Please install vmdebootstrap.)")
......@@ -305,7 +324,7 @@ def main(provider='virtualbox', verbose=False, dry_run=False):
workdir = tmpdir
# main parameters for this image
params = init_params(provider, workdir=workdir)
params = init_params(provider, debver, workdir=workdir)
logging.debug('image parameters: {}'
.format(json.dumps(params, indent=2)))
......@@ -332,6 +351,11 @@ if __name__ == '__main__':
help="Spew out even more information than normal")
parser.add_argument("-q", "--quiet", action="store_true", default=False,
help="Restrict output to warnings and errors")
parser.add_argument('-t', '--target', default="jessie64",
help="target debian version. "
"defaults to 'jessie64'. "
"(supported: " +
', '.join(SUPPORTED_DEBVERS) + ')')
parser.add_argument('-p', '--provider', default='virtualbox',
help="target vagrant provider. "
"defaults to 'virtualbox'. "
......@@ -356,6 +380,7 @@ if __name__ == '__main__':
try:
main(dry_run=options.dry_run,
provider=options.provider,
debver=options.target,
verbose=options.verbose)
except BaseboxException as e:
logging.critical(e)
......@@ -2,16 +2,23 @@
set -e
VMROOT=$1
echo '{username} ALL=(ALL) NOPASSWD: ALL' >> $VMROOT/etc/sudoers
DEB_DISTRO="{deb_distro}"
USERNAME="{username}"
USERHOME="$VMROOT/home/$USERNAME"
echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" >> $VMROOT/etc/sudoers
VGRNT_UID=`ls -ln $VMROOT/home | grep vagrant | awk '{{print $3}}'`
VGRNT_GID=`ls -ln $VMROOT/home | grep vagrant | awk '{{print $4}}'`
mkdir $VMROOT/home/vagrant/.ssh
chmod 700 $VMROOT/home/vagrant/.ssh
chown $VGRNT_UID:$VGRNT_GID $VMROOT/home/vagrant/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant_insecure_public_key" > $VMROOT/home/vagrant/.ssh/authorized_keys
chmod 600 $VMROOT/home/vagrant/.ssh/authorized_keys
chown $VGRNT_UID:$VGRNT_GID $VMROOT/home/vagrant/.ssh/authorized_keys
echo 'DEBUG +++ DEBUG +++ DEBUG +++ DEBUG +++ DEBUG +++ DEBUG +++ DEBUG'
ls -al $VMROOT/home/vagrant/
ls -al $VMROOT/home/vagrant/.ssh
VGRNT_UID=`ls -ln $VMROOT/home | grep $USERNAME | awk '{{print $3}}'`
VGRNT_GID=`ls -ln $VMROOT/home | grep $USERNAME | awk '{{print $4}}'`
mkdir $VMROOT/home/$USERNAME/.ssh
chmod 700 $VMROOT/home/$USERNAME/.ssh
chown $VGRNT_UID:$VGRNT_GID $USERHOME/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant_insecure_public_key" > $USERHOME/.ssh/authorized_keys
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
fi
Vagrant.configure("2") do |config|
config.vm.box = "fdroid-jessie64"
config.vm.box = "fdroid-stretch64"
config.vm.provider :libvirt do |libvirt|
libvirt.driver = "kvm"
......
Vagrant.configure("2") do |config|
config.vm.box = "fdroid-jessie64"
config.vm.box = "fdroid-stretch64"
end
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