From 7325a9371dbd64ce8099bd733342f178bff34714 Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Fri, 29 Apr 2016 17:07:16 +0200 Subject: [PATCH] Minimal solar VM packer template Alpine linux as a base, vbox and libvirt Change-Id: Iaa37b1ae02b4b0d22fc01fbeff5c6ce96e0b2699 --- bootstrap/alpine/README.md | 2 + bootstrap/alpine/http/answers_qemu | 16 +++ bootstrap/alpine/http/answers_vbox | 16 +++ bootstrap/alpine/scripts/00base.sh | 19 +++ bootstrap/alpine/scripts/01alpine.sh | 5 + bootstrap/alpine/scripts/01networking.sh | 5 + bootstrap/alpine/scripts/02sshd.sh | 10 ++ bootstrap/alpine/scripts/03vagrant.sh | 25 ++++ bootstrap/alpine/scripts/04sudoers.sh | 7 ++ bootstrap/alpine/scripts/90virtualbox.sh | 53 ++++++++ bootstrap/alpine/scripts/98solar.sh | 54 +++++++++ bootstrap/alpine/scripts/99minimize.sh | 11 ++ bootstrap/alpine/sh_vars | 15 +++ bootstrap/alpine/solar-minimal.json | 147 +++++++++++++++++++++++ 14 files changed, 385 insertions(+) create mode 100644 bootstrap/alpine/README.md create mode 100644 bootstrap/alpine/http/answers_qemu create mode 100644 bootstrap/alpine/http/answers_vbox create mode 100644 bootstrap/alpine/scripts/00base.sh create mode 100644 bootstrap/alpine/scripts/01alpine.sh create mode 100644 bootstrap/alpine/scripts/01networking.sh create mode 100644 bootstrap/alpine/scripts/02sshd.sh create mode 100644 bootstrap/alpine/scripts/03vagrant.sh create mode 100644 bootstrap/alpine/scripts/04sudoers.sh create mode 100644 bootstrap/alpine/scripts/90virtualbox.sh create mode 100755 bootstrap/alpine/scripts/98solar.sh create mode 100644 bootstrap/alpine/scripts/99minimize.sh create mode 100644 bootstrap/alpine/sh_vars create mode 100644 bootstrap/alpine/solar-minimal.json diff --git a/bootstrap/alpine/README.md b/bootstrap/alpine/README.md new file mode 100644 index 00000000..ad74b08d --- /dev/null +++ b/bootstrap/alpine/README.md @@ -0,0 +1,2 @@ +This directory is adjusted and modified version of: +https://github.com/maier/packer-templates/tree/master/alpine3.3 diff --git a/bootstrap/alpine/http/answers_qemu b/bootstrap/alpine/http/answers_qemu new file mode 100644 index 00000000..210705f3 --- /dev/null +++ b/bootstrap/alpine/http/answers_qemu @@ -0,0 +1,16 @@ +KEYMAPOPTS="us us" +HOSTNAMEOPTS="-n solar" +INTERFACESOPTS="auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet dhcp + hostname solar +" +DNSOPTS="-d local -n 8.8.8.8 8.8.4.4" +TIMEZONEOPTS="-z UTC" +PROXYOPTS="none" +APKREPOSOPTS="-r" +SSHDOPTS="-c openssh" +NTPOPTS="-c openntpd" +DISKOPTS="-s 0 -m sys /dev/vda" diff --git a/bootstrap/alpine/http/answers_vbox b/bootstrap/alpine/http/answers_vbox new file mode 100644 index 00000000..f6ef4ff1 --- /dev/null +++ b/bootstrap/alpine/http/answers_vbox @@ -0,0 +1,16 @@ +KEYMAPOPTS="us us" +HOSTNAMEOPTS="-n solar" +INTERFACESOPTS="auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet dhcp + hostname solar +" +DNSOPTS="-d local -n 8.8.8.8 8.8.4.4" +TIMEZONEOPTS="-z UTC" +PROXYOPTS="none" +APKREPOSOPTS="-r" +SSHDOPTS="-c openssh" +NTPOPTS="-c openntpd" +DISKOPTS="-s 0 -m sys /dev/sda" diff --git a/bootstrap/alpine/scripts/00base.sh b/bootstrap/alpine/scripts/00base.sh new file mode 100644 index 00000000..066c4654 --- /dev/null +++ b/bootstrap/alpine/scripts/00base.sh @@ -0,0 +1,19 @@ +set -ux + +apk upgrade -U --available + +source /etc/os-release + +cat << EOF > /etc/motd + +$PRETTY_NAME ($VERSION_ID) Development Environment + +Built for use with Vagrant using: + + +See the Alpine Wiki for how-to guides and +general information about administrating +Alpine systems and development. +See + +EOF diff --git a/bootstrap/alpine/scripts/01alpine.sh b/bootstrap/alpine/scripts/01alpine.sh new file mode 100644 index 00000000..058441d9 --- /dev/null +++ b/bootstrap/alpine/scripts/01alpine.sh @@ -0,0 +1,5 @@ +set -ux + +# nothing special required + +exit 0 \ No newline at end of file diff --git a/bootstrap/alpine/scripts/01networking.sh b/bootstrap/alpine/scripts/01networking.sh new file mode 100644 index 00000000..058441d9 --- /dev/null +++ b/bootstrap/alpine/scripts/01networking.sh @@ -0,0 +1,5 @@ +set -ux + +# nothing special required + +exit 0 \ No newline at end of file diff --git a/bootstrap/alpine/scripts/02sshd.sh b/bootstrap/alpine/scripts/02sshd.sh new file mode 100644 index 00000000..db16f6fa --- /dev/null +++ b/bootstrap/alpine/scripts/02sshd.sh @@ -0,0 +1,10 @@ +set -eux + +# add in order to allow packer ssh access to provision +# the system, remove here to make box more secure +sed -i '/^PermitRootLogin yes/d' /etc/ssh/sshd_config + +# make 'vagrant ssh' connections faster +echo "UseDNS no" >> /etc/ssh/sshd_config + + diff --git a/bootstrap/alpine/scripts/03vagrant.sh b/bootstrap/alpine/scripts/03vagrant.sh new file mode 100644 index 00000000..d0b817f9 --- /dev/null +++ b/bootstrap/alpine/scripts/03vagrant.sh @@ -0,0 +1,25 @@ +set -exu + +date > /etc/vagrant_box_build_time + +# +# bash for vagrant (default shell is bash) +# doesn't look like there is an easy way for vagrant guest +# plugin to register a default shell. easier than always +# having to *remember* to configure `ssh.shell` for +# alpine boxes. +# +# cURL for initial vagrant key install from vagrant github repo. +# on first 'vagrant up', overwritten with a local, secure key. +# +apk add bash curl + +adduser -D vagrant +echo "vagrant:vagrant" | chpasswd + +mkdir -pm 700 /home/vagrant/.ssh + +curl -sSo /home/vagrant/.ssh/authorized_keys 'https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub' + +chown -R vagrant:vagrant /home/vagrant/.ssh +chmod -R go-rwsx /home/vagrant/.ssh diff --git a/bootstrap/alpine/scripts/04sudoers.sh b/bootstrap/alpine/scripts/04sudoers.sh new file mode 100644 index 00000000..81767096 --- /dev/null +++ b/bootstrap/alpine/scripts/04sudoers.sh @@ -0,0 +1,7 @@ +set -eux + +apk add sudo +adduser vagrant wheel + +echo "Defaults exempt_group=wheel" > /etc/sudoers +echo "%wheel ALL=NOPASSWD:ALL" >> /etc/sudoers diff --git a/bootstrap/alpine/scripts/90virtualbox.sh b/bootstrap/alpine/scripts/90virtualbox.sh new file mode 100644 index 00000000..47eadd0d --- /dev/null +++ b/bootstrap/alpine/scripts/90virtualbox.sh @@ -0,0 +1,53 @@ +set -eux +echo "VBoxGuestAdditions currently do not build or install on Alpine Linux." +exit 0 +# +# # +# # VBoxGuestAdditions fails to install. +# # +# # Alpine is intended to be 'minimal' so +# # there are certain things VBGA +# # 1. needs +# # 2. *assumes* are available +# # 3. or function a specific way +# # which is, not yet, the case... +# # +# +# mkdir -p /mnt/virtualbox +# retval=$? +# [ $retval -eq 0 ] || exit $retval +# +# modprobe loop +# retval=$? +# [ $retval -eq 0 ] || exit $retval +# +# LOOP=`losetup -f` +# retval=$? +# [ $retval -eq 0 ] || exit $retval +# +# losetup $LOOP /root/VBoxGuestAdditions.iso +# retval=$? +# [ $retval -eq 0 ] || exit $retval +# +# mount -t iso9660 -o ro $LOOP /mnt/virtualbox +# retval=$? +# [ $retval -eq 0 ] || exit $retval +# +# # current error 'unable to determine library path.' +# # "ldconfig -v" does not result in a list of valid +# # library paths (it is actually a shell script which +# # silently ignores -v). +# # +# # there are other issues as well, which have been +# # open with oracle/virtualbox for several years. +# # without forward progress (according to search +# # results and skimming through various discussions). +# sh /mnt/virtualbox/VBoxLinuxAdditions.run +# retval=$? +# [ $retval -eq 0 ] || exit $retval +# +# ln -s /opt/VBoxGuestAdditions-*/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions +# umount /mnt/virtualbox +# rm -rf /root/VBoxGuestAdditions.iso +# +# # END diff --git a/bootstrap/alpine/scripts/98solar.sh b/bootstrap/alpine/scripts/98solar.sh new file mode 100755 index 00000000..95ee4482 --- /dev/null +++ b/bootstrap/alpine/scripts/98solar.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -ex + +# install required stuff +apk add --no-cache py-pip openssl git gcc build-base python-dev libffi libffi-dev + +# install packages for solar transports +# (sshpass -> password passing for SSH commands) +apk add --no-cache rsync sshpass + +mkdir -p /opt +cd /opt +git clone https://github.com/openstack/solar.git +cd /opt/solar +sudo sed -i '/ansible.*/ s/^#*/#/' requirements.txt +pip install pbr && pip install -e . +chown -R vagrant: /opt/solar +mkdir -p /etc/solar +echo "solar_db: sqlite:////home/vagrant/solar.db" > /etc/solar/solar.yaml +mkdir -p /var/lib/solar/repositories +chown -R vagrant: /var/lib/solar/repositories + +# ssh config +cat <>/home/vagrant/.ssh/config +Host * + StrictHostKeyChecking no +EOF + +# worker +cat <>/etc/init.d/solar-worker +#!/sbin/runscript +# $Header: $ + +depend() { + need net + need localmount +} + +start() { + ebegin "Starting solar-worker" + exec start-stop-daemon -b --chdir /tmp --start --user vagrant --make-pidfile --pidfile /tmp/solar-worker.pid --exec solar-worker + eend $? +} + +stop() { + ebegin "Stopping solar-worker" + exec start-stop-daemon --stop --user vagrant --pidfile /tmp/solar-worker.pid --exec solar-worker + eend $? +} + +EOF +chmod +x /etc/init.d/solar-worker +rc-update add solar-worker default diff --git a/bootstrap/alpine/scripts/99minimize.sh b/bootstrap/alpine/scripts/99minimize.sh new file mode 100644 index 00000000..fca5d930 --- /dev/null +++ b/bootstrap/alpine/scripts/99minimize.sh @@ -0,0 +1,11 @@ +set -ux + +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY +# Block until the empty file has been removed, otherwise, Packer +# will try to kill the box while the disk is still full and that's bad +sync +sync +sync + +exit 0 diff --git a/bootstrap/alpine/sh_vars b/bootstrap/alpine/sh_vars new file mode 100644 index 00000000..9dde40d1 --- /dev/null +++ b/bootstrap/alpine/sh_vars @@ -0,0 +1,15 @@ + +dist_name="alpine" +dist_vers="3.3" +dist_arch="x86_64" + +# local or remote +build_type="local" + +# set in .bashrc +# ATLAS_USER_NAME="maier" +# +# default in atlas.sh is fine +# ATLAS_BOX_NAME="${dist_name}-${dist_vers}-${dist_arch}" + +# END diff --git a/bootstrap/alpine/solar-minimal.json b/bootstrap/alpine/solar-minimal.json new file mode 100644 index 00000000..e6363658 --- /dev/null +++ b/bootstrap/alpine/solar-minimal.json @@ -0,0 +1,147 @@ +{ + "description": "Build base Alpine Linux x86_64", + "provisioners": [ + { + "type": "shell", + "scripts": [ + "scripts/00base.sh", + "scripts/01alpine.sh", + "scripts/01networking.sh", + "scripts/02sshd.sh", + "scripts/03vagrant.sh", + "scripts/04sudoers.sh", + "scripts/90virtualbox.sh", + "scripts/98solar.sh", + "scripts/99minimize.sh" + ], + "override": { + "virtualbox-iso": { + "execute_command": "/bin/sh '{{.Path}}'" + } + } + } + ], + "builders": [ + { + "type": "virtualbox-iso", + "virtualbox_version_file": ".vbox_version", + + "guest_additions_mode": "disable", + "guest_os_type": "Linux26_64", + "headless": true, + "disk_size": 1024, + "http_directory": "http", + + "iso_url": "http://wiki.alpinelinux.org/cgi-bin/dl.cgi/v3.3/releases/x86_64/alpine-3.3.3-x86_64.iso", + "iso_checksum": "af766ac6221c6f5b471ca388be22df81ac6f21be37486ba6846f115d1798528a", + "iso_checksum_type": "sha256", + + "communicator": "ssh", + "ssh_username": "root", + "ssh_password": "vagrant", + "ssh_wait_timeout": "30m", + "shutdown_command": "/sbin/poweroff", + + "boot_wait": "30s", + "boot_command": [ + "root", + "ifconfig eth0 up && udhcpc -i eth0", + "wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers_vbox", + "setup-alpine -f answers_vbox", + "vagrant", + "vagrant", + "", + "", + "y", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "rc-service sshd stop", + "mount /dev/sda3 /mnt", + "echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config", + "umount /mnt", + "reboot" + ], + + "hard_drive_interface": "sata", + "vboxmanage": [ + ["modifyvm", "{{.Name}}", "--memory", "512"], + ["modifyvm", "{{.Name}}", "--cpus", "1"] + ] + + }, { + "type": "qemu", + "headless": true, + "disk_size": 1024, + "accelerator": "kvm", + "format": "qcow2", + "http_directory": "http", + + "iso_url": "http://wiki.alpinelinux.org/cgi-bin/dl.cgi/v3.3/releases/x86_64/alpine-3.3.3-x86_64.iso", + "iso_checksum": "af766ac6221c6f5b471ca388be22df81ac6f21be37486ba6846f115d1798528a", + "iso_checksum_type": "sha256", + + "communicator": "ssh", + "ssh_username": "root", + "ssh_password": "vagrant", + "ssh_wait_timeout": "30m", + "shutdown_command": "/sbin/poweroff", + + "boot_wait": "30s", + "boot_command": [ + "root", + "ifconfig eth0 up && udhcpc -i eth0", + "wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers_qemu", + "setup-alpine -f answers_qemu", + "vagrant", + "vagrant", + "", + "", + "y", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "rc-service sshd stop", + "mount /dev/vda3 /mnt", + "echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config", + "umount /mnt", + "reboot" + ], + "qemuargs": [ + [ + "-m", + "512M" + ], + [ + "-smp", + "1" + ] + ] + } + ], + "post-processors": [ + [{ + "type": "vagrant", + "keep_input_artifact": false, + "only": ["virtualbox-iso"], + "output": "solar-minimal-virtualbox.box" + },{ + "type": "vagrant", + "keep_input_artifact": true, + "only": ["qemu"], + "output": "solar-minimal-qemu.box" + }] + ] +}