diff --git a/README.md b/README.md index 0b5efcd..2af08ed 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ There are currently 3 options to start the workshop by yourself: - us-west-1: ami-07f8ee67 - us-east-1: ami-1162bc6c - eu-central-1: ami-9a663471 - 1. We provide a [packer template](https://www.packer.io/) so you can create - your own AMI. + 1. We provide [packer templates](https://www.packer.io/) so you can create + your own AMI or VMware OVA. 1. We have a [Vagrantfile](https://www.vagrantup.com/) for you to run using your favorite virtual machine hypervisor (NOTE: not yet fully tested). diff --git a/packer/.gitignore b/packer/.gitignore new file mode 100644 index 0000000..cb39c67 --- /dev/null +++ b/packer/.gitignore @@ -0,0 +1,3 @@ +packer_cache/ +packer-rubber-docker-ubuntu-16.04-vmware/ +rubber-docker-ubuntu-16.04.ova diff --git a/packer/README.md b/packer/README.md new file mode 100644 index 0000000..715d85e --- /dev/null +++ b/packer/README.md @@ -0,0 +1,43 @@ +# Building Rubber-Docker Workshop VMs + +## Overview + +This directory has two packer.json files that you can use to construct +VMs for the lab. You'll need to [download +packer](https://www.packer.io/downloads.html) or [build it from +source](https://www.packer.io/docs/install/index.html#compiling-from-source). + +Login using ubuntu/ubuntu for both VMs. + +## AWS AMI + +Set your AWS credentials as environmental variables and fill in a valid +subnet ID from your VPC in rubber-docker-aws.json, then execute: +``` +packer build rubber-docker-aws.json +``` +Note that the source AMI is not accessible outside the region given +in the packer build file. + +## VMware OVA + +Build on Mac OS X. In addition to packer you'll need VMware Fusion +and ovftool. Execute the following: + +``` +packer build rubber-docker-vmware.json +ovftool packer-rubber-docker-ubuntu-16.04-vmware/rubber-docker-ubuntu-16.04.vmx rubber-docker-ubuntu-16.04.ova +``` +The OVA is optional. You can also just start the VM directly in +VMware Fusion. + +Note: The external network interface name on the VM may switch from +ens33 to ens32 when you export to ovftool and boot. If this occurs +edit /etc/network/interfaces and switch the interface name to the +correct value. + +## Licensing + +VMware packer file rubber-docker-vmware.json and preseed.cfg are derived +from similar files published at +https://github.com/geerlingguy/packer-ubuntu-1604 under the [MIT license](https://opensource.org/licenses/MIT). diff --git a/packer/bootstrap.sh b/packer/bootstrap.sh index 6cbbfc5..554cba1 100644 --- a/packer/bootstrap.sh +++ b/packer/bootstrap.sh @@ -20,16 +20,21 @@ fi sleep 10 # Install packages +echo "Installing packages..." +apt-get -y install software-properties-common add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 0EBFCD88 apt-get update -apt-get -y install docker-ce stress python-dev build-essential cmake htop ipython python-pip git +apt-get -y install docker-ce stress python-dev build-essential cmake htop ipython python-pip git vim # Include the memory and memsw cgroups -sed -i.bak 's|^kernel.*$|\0 cgroup_enable=memory swapaccount=1|' /boot/grub/menu.lst +if [ -f /boot/grub/menu.lst ]; then + # Not available in recent Ubuntu builds, so this is optional. + sed -i.bak 's|^kernel.*$|\0 cgroup_enable=memory swapaccount=1|' /boot/grub/menu.lst +fi sed -i -r 's|GRUB_CMDLINE_LINUX="(.*)"|GRUB_CMDLINE_LINUX="\1 cgroup_enable=memory swapaccount=1"|' /etc/default/grub update-grub @@ -45,7 +50,7 @@ systemctl restart docker usermod -G docker -a ubuntu # Clone git repo -mkdir /workshop +mkdir -p /workshop pushd /workshop git clone https://github.com/Fewbytes/rubber-docker.git pip install -r rubber-docker/requirements.txt @@ -101,4 +106,4 @@ echo "Installing plugins using Vundle" echo | echo | vim +PluginInstall +qall &>/dev/null echo "Vundle done" python ~/.vim/bundle/YouCompleteMe/install.py -EOS \ No newline at end of file +EOS diff --git a/packer/http/preseed.cfg b/packer/http/preseed.cfg new file mode 100644 index 0000000..4151aa2 --- /dev/null +++ b/packer/http/preseed.cfg @@ -0,0 +1,45 @@ +choose-mirror-bin mirror/http/proxy string +d-i base-installer/kernel/override-image string linux-server +d-i clock-setup/utc boolean true +d-i clock-setup/utc-auto boolean true +d-i finish-install/reboot_in_progress note +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i partman-auto/disk string /dev/sda +d-i partman-auto-lvm/guided_size string max +d-i partman-auto/choose_recipe select atomic +d-i partman-auto/method string lvm +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/confirm_write_new_label boolean true +d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common +d-i pkgsel/install-language-support boolean false +d-i pkgsel/update-policy select none +d-i pkgsel/upgrade select full-upgrade +d-i time/zone string UTC +tasksel tasksel/first multiselect standard, ubuntu-server + +d-i console-setup/ask_detect boolean false +d-i keyboard-configuration/layoutcode string us +d-i keyboard-configuration/modelcode string pc105 +d-i debian-installer/locale string en_US + +# Create ubuntu user account. +d-i passwd/user-fullname string ubuntu +d-i passwd/username string ubuntu +d-i passwd/user-password password ubuntu +d-i passwd/user-password-again password ubuntu +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false +d-i passwd/user-default-groups ubuntu sudo +d-i passwd/user-uid string 900 + +# Enable passwordless sudo for ubuntu so other config scripts can work. +d-i preseed/late_command string \ + echo 'ubuntu ALL=(ALL) NOPASSWD: ALL' > /target/etc/sudoers.d/ubuntu ; \ + in-target chmod 440 /etc/sudoers.d/ubuntu ; diff --git a/packer/rubber-docker.json b/packer/rubber-docker-aws.json similarity index 100% rename from packer/rubber-docker.json rename to packer/rubber-docker-aws.json diff --git a/packer/rubber-docker-vmware.json b/packer/rubber-docker-vmware.json new file mode 100644 index 0000000..37b7a47 --- /dev/null +++ b/packer/rubber-docker-vmware.json @@ -0,0 +1,63 @@ +{ + "builders": [ + { + "type": "vmware-iso", + "boot_command": [ + "", + "", + "", + "", + "/install/vmlinuz", + " auto", + " console-setup/ask_detect=false", + " console-setup/layoutcode=us", + " debconf/frontend=noninteractive", + " debian-installer=en_US", + " fb=false", + " initrd=/install/initrd.gz", + " keyboard-configuration/layout=USA", + " keyboard-configuration/variant=USA", + " locale=en_US", + " netcfg/get_domain=vm", + " netcfg/get_hostname=rubber-docker", + " grub-installer/bootdev=/dev/sda", + " noapic", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", + " -- ", + "" + ], + "boot_wait": "10s", + "disk_size": 20480, + "guest_os_type": "ubuntu-64", + "headless": true, + "http_directory": "http", + "iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.4-server-amd64.iso", + "iso_checksum_type": "sha256", + "iso_checksum": "0a03608988cfd2e50567990dc8be96fb3c501e198e2e6efcb846d89efc7b89f2", + "output_directory": "packer-rubber-docker-ubuntu-16.04-vmware", + "shutdown_command": "echo 'ubuntu'|sudo -S shutdown -P now", + "ssh_password": "ubuntu", + "ssh_port": 22, + "ssh_username": "ubuntu", + "ssh_wait_timeout": "10000s", + "tools_upload_flavor": "linux", + "vm_name": "rubber-docker-ubuntu-16.04", + "vmx_data": { + "cpuid.coresPerSocket": "1", + "memsize": "1024", + "numvcpus": "1" + } + } + ], + "provisioners": [ + { + "type": "file", + "source": "vimrc", + "destination": "/tmp/vimrc" + }, + { + "type": "shell", + "script": "bootstrap.sh" + } + ] +}