diff --git a/buildozer/tools/packer/README.md b/buildozer/tools/packer/README.md new file mode 100644 index 0000000..89798b9 --- /dev/null +++ b/buildozer/tools/packer/README.md @@ -0,0 +1,20 @@ +# Introduction + +It is an example packer template based on netboot iso that adds packages for xubuntu and buildozer. + +# Configure + +You want to edit `http/preseed.cfg` and `template.json` before building an image. + +# Build + +`packer build template.json` + +# Testing the image after it's built. + +`./launch` + +# TODO + + - [compact the image](https://crysol.github.io/recipe/2013-10-15/virtualbox-compact-vmdk-images/) + - trigger a build, torrent creation and gdrive upload when buildozer is released diff --git a/buildozer/tools/packer/http/preseed.cfg b/buildozer/tools/packer/http/preseed.cfg new file mode 100644 index 0000000..11c1f32 --- /dev/null +++ b/buildozer/tools/packer/http/preseed.cfg @@ -0,0 +1,100 @@ +### Options to set on the command line +d-i debian-installer/locale string en_US.UTF-8 +d-i console-setup/ask_detect boolean false +d-i keyboard-configuration/layoutcode string us +d-i keyboard-configuration/variant string us + +### Network +d-i netcfg/choose_interface select auto + +d-i netcfg/get_hostname string ubuntu +d-i netcfg/get_domain string local + +d-i netcfg/wireless_wep string + +### Mirror +d-i mirror/country string manual +d-i mirror/http/hostname string jp.archive.ubuntu.com +d-i mirror/http/directory string /ubuntu +d-i mirror/http/proxy string + +### Time +d-i time/zone string UTC +d-i clock-setup/utc boolean true + +### Partitioning +d-i partman-auto/method string lvm +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-md/device_remove_md boolean true + +# Write the changes to disks and configure LVM? +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true + +d-i partman-auto-lvm/guided_size string max +d-i partman-auto/choose_recipe select atomic +d-i partman/default_filesystem string ext4 + +# This makes partman automatically partition without confirmation, provided +# that you told it what to do using one of the methods above. +#d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +### User Account + +# root account +#d-i passwd/root-login boolean true +#d-i passwd/make-user boolean false +#d-i passwd/root-password password abcdabcd +#d-i passwd/root-password-again password abcdabcd + +# a user account +d-i passwd/user-fullname string kivy +d-i passwd/username string kivy +d-i passwd/user-password password kivy +d-i passwd/user-password-again password kivy + +# you might want to configure auto login. +#d-i passwd/auto-login boolean true + +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false + +# You can choose to install restricted and universe software, or to install +# software from the backports repository. +d-i apt-setup/restricted boolean true +d-i apt-setup/universe boolean true +# d-i apt-setup/backports boolean true + +# Uncomment this if you don't want to use a network mirror. +# d-i apt-setup/use_mirror boolean false + +# Select which update services to use; define the mirrors to be used. +# Values shown below are the normal defaults. +d-i apt-setup/services-select multiselect security +d-i apt-setup/security_host string security.ubuntu.com +d-i apt-setup/security_path string /ubuntu + +### Packages +tasksel tasksel/first multiselect xubuntu-desktop + +d-i pkgsel/include string openssh-server build-essential ibus-hangul +d-i pkgsel/upgrade select none +d-i pkgsel/update-policy select none +d-i pkgsel/language-packs multiselect en, ko +# required by ubuntu server iso, but not required by netboot iso +d-i pkgsel/install-language-support boolean true + +popularity-contest popularity-contest/participate boolean false + +d-i lilo-installer/skip boolean true + +### Bootloader +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true + +### Finishing +d-i finish-install/reboot_in_progress note diff --git a/buildozer/tools/packer/launch b/buildozer/tools/packer/launch new file mode 100644 index 0000000..f540667 --- /dev/null +++ b/buildozer/tools/packer/launch @@ -0,0 +1,3 @@ +#!/bin/sh + +/usr/bin/qemu-system-x86_64 -redir tcp:3213::22 -vga qxl -display sdl -netdev user,id=user.0 -device virtio-net,netdev=user.0 -drive file=output-from-netboot-iso/ubuntu.qcow2,if=virtio -boot once=d -name sanitytest -machine type=pc-1.0,accel=kvm -m 512M -vnc 0.0.0.0:47 diff --git a/buildozer/tools/packer/scripts/additional-packages.sh b/buildozer/tools/packer/scripts/additional-packages.sh new file mode 100644 index 0000000..70d12fa --- /dev/null +++ b/buildozer/tools/packer/scripts/additional-packages.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux + +wget http://bootstrap.pypa.io/get-pip.py +python get-pip.py +rm get-pip.py +apt-get -y install git openjdk-7-jdk --no-install-recommends zlib1g-dev +pip install cython buildozer diff --git a/buildozer/tools/packer/scripts/minimize.sh b/buildozer/tools/packer/scripts/minimize.sh new file mode 100644 index 0000000..6955ede --- /dev/null +++ b/buildozer/tools/packer/scripts/minimize.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Remove APT cache +apt-get -y --purge autoremove +apt-get -y clean + +# Cleanup log files +find /var/log -type f | while read f; do echo -ne '' > $f; done; + +# Whiteout root +count=`df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}'`; +let count-- +dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count; +rm /tmp/whitespace; + +# Whiteout /boot +count=`df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}'`; +let count-- +dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count; +rm /boot/whitespace; + +swappart=`cat /proc/swaps | tail -n1 | awk -F ' ' '{print $1}'` +swapoff $swappart; +dd if=/dev/zero of=$swappart; +mkswap $swappart; +swapon $swappart; + +# Zero free space to aid VM compression +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY + +# Remove bash history +unset HISTFILE +rm -f /root/.bash_history diff --git a/buildozer/tools/packer/template.json b/buildozer/tools/packer/template.json new file mode 100644 index 0000000..718b5ab --- /dev/null +++ b/buildozer/tools/packer/template.json @@ -0,0 +1,46 @@ +{ + "variables": { + "disk_size": "20480", + "disk_format": "ovf", + "ssh_username": "kivy", + "ssh_password": "kivy", + "hostname": "ubuntu" + }, + "description": "Build a Xubuntu Virtual Machine", + "builders": [{ + "type": "virtualbox-iso", + "name": "from-netboot-iso", + "http_directory": "http", + "iso_checksum": "4c58dcf09083cd3aa602eb1b79810a0ff58b7c21", + "iso_checksum_type": "sha1", + "iso_url": "http://archive.ubuntu.com/ubuntu/dists/vivid/main/installer-i386/current/images/netboot/mini.iso", + "ssh_username": "{{user `ssh_username`}}", + "ssh_password": "{{user `ssh_password`}}", + "boot_wait": "3s", + "boot_command": [ + "", + "/linux noapic preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed.cfg ", + "hostname={{user `hostname`}} ", + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", + "fb=false ", + "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", + "keyboard-configuration/variant=USA console-setup/ask_detect=false ", + "initrd=/initrd.gz -- " + ], + "disk_size": "{{user `disk_size`}}", + "format": "{{user `disk_format`}}", + "headless": false, + "shutdown_command": "echo {{user `ssh_password`}} | sudo -S shutdown -P now", + "vm_name": "ubuntu", + "ssh_wait_timeout": "120m" + }], + "provisioners": [{ + "type": "shell", + "execute_command": "echo {{user `ssh_password`}} | {{ .Vars }} sudo -E -S sh '{{ .Path }}'", + "scripts": [ + "scripts/additional-packages.sh", + "scripts/minimize.sh" + ] + }], + "post-processors": [] +}