Skip to content

Commit

Permalink
Add packer template and documentation to generate VMware OVAs
Browse files Browse the repository at this point in the history
Added a packer template to generate lab VM on VMware using Ubuntu
16.04 as base.  Made minor changes to bootstrap.sh to accomodate
more recent Ubuntu release including installing extra packages
required for Ubuntu 16.04 and to skip update of grub menu.lst, which
no longer exists. Added preseed.cfg file to create sudo-enabled
ubuntu account required for lab.  Added README.md to document usage
and edited top-level README.md to refer to VMware as well as AWS.
  • Loading branch information
Robert Hodges committed Apr 20, 2018
1 parent 01ce4e4 commit 83a37a6
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
3 changes: 3 additions & 0 deletions packer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packer_cache/
packer-rubber-docker-ubuntu-16.04-vmware/
rubber-docker-ubuntu-16.04.ova
43 changes: 43 additions & 0 deletions packer/README.md
Original file line number Diff line number Diff line change
@@ -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).
13 changes: 9 additions & 4 deletions packer/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
EOS
45 changes: 45 additions & 0 deletions packer/http/preseed.cfg
Original file line number Diff line number Diff line change
@@ -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 ;
File renamed without changes.
63 changes: 63 additions & 0 deletions packer/rubber-docker-vmware.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"builders": [
{
"type": "vmware-iso",
"boot_command": [
"<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"/install/vmlinuz<wait>",
" auto<wait>",
" console-setup/ask_detect=false<wait>",
" console-setup/layoutcode=us<wait>",
" debconf/frontend=noninteractive<wait>",
" debian-installer=en_US<wait>",
" fb=false<wait>",
" initrd=/install/initrd.gz<wait>",
" keyboard-configuration/layout=USA<wait>",
" keyboard-configuration/variant=USA<wait>",
" locale=en_US<wait>",
" netcfg/get_domain=vm<wait>",
" netcfg/get_hostname=rubber-docker<wait>",
" grub-installer/bootdev=/dev/sda<wait>",
" noapic<wait>",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
" -- <wait>",
"<enter><wait>"
],
"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"
}
]
}

0 comments on commit 83a37a6

Please sign in to comment.