Skip to content

Commit c01a3df

Browse files
author
Robert Hodges
committed
Add packer template and documentation to generate VMware OVAs
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.
1 parent 01ce4e4 commit c01a3df

File tree

7 files changed

+203
-6
lines changed

7 files changed

+203
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ There are currently 3 options to start the workshop by yourself:
2929
- us-west-1: ami-07f8ee67
3030
- us-east-1: ami-1162bc6c
3131
- eu-central-1: ami-9a663471
32-
1. We provide a [packer template](https://www.packer.io/) so you can create
33-
your own AMI.
32+
1. We provide [packer templates](https://www.packer.io/) so you can create
33+
your own AMI or VMware OVA.
3434
1. We have a [Vagrantfile](https://www.vagrantup.com/) for you to run using
3535
your favorite virtual machine hypervisor (NOTE: not yet fully tested).
3636

packer/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packer_cache/
2+
packer-rubber-docker-ubuntu-16.04-vmware/
3+
rubber-docker-ubuntu-16.04.ova

packer/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Building Rubber-Docker Workshop VMs
2+
3+
## Overview
4+
5+
This directory has two packer.json files that you can use to construct
6+
VMs for the lab. You'll need to [download
7+
packer](https://www.packer.io/downloads.html) or [build it from
8+
source](https://www.packer.io/docs/install/index.html#compiling-from-source).
9+
10+
Login using ubuntu/ubuntu for both VMs.
11+
12+
## AWS AMI
13+
14+
Set your AWS credentials as environmental variables and fill in a valid
15+
subnet ID from your VPC in rubber-docker-aws.json, then execute:
16+
```
17+
packer build rubber-docker-aws.json
18+
```
19+
Note that the source AMI is not accessible outside the region given
20+
in the packer build file.
21+
22+
## VMware OVA
23+
24+
Build on Mac OS X. In addition to packer you'll need VMware Fusion
25+
and ovftool. Execute the following:
26+
27+
```
28+
packer build rubber-docker-vmware.json
29+
ovftool packer-rubber-docker-ubuntu-16.04-vmware/rubber-docker-ubuntu-16.04.vmx rubber-docker-ubuntu-16.04.ova
30+
```
31+
The OVA is optional. You can also just start the VM directly in
32+
VMware Fusion.
33+
34+
Note: The external network interface name on the VM may switch from
35+
ens33 to ens32 when you export to ovftool and boot. If this occurs
36+
edit /etc/network/interfaces and switch the interface name to the
37+
correct value.
38+
39+
## Licensing
40+
41+
VMware packer file rubber-docker-vmware.json and preseed.cfg are derived
42+
from similar files published at
43+
https://github.com/geerlingguy/packer-ubuntu-1604 under the [MIT license]
44+
(https://opensource.org/licenses/MIT).

packer/bootstrap.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ fi
2020
sleep 10
2121

2222
# Install packages
23+
echo "Installing packages..."
24+
apt-get -y install software-properties-common
2325
add-apt-repository \
2426
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
2527
$(lsb_release -cs) \
2628
stable"
2729
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 0EBFCD88
2830
apt-get update
29-
apt-get -y install docker-ce stress python-dev build-essential cmake htop ipython python-pip git
31+
apt-get -y install docker-ce stress python-dev build-essential cmake htop ipython python-pip git vim
3032

3133
# Include the memory and memsw cgroups
32-
sed -i.bak 's|^kernel.*$|\0 cgroup_enable=memory swapaccount=1|' /boot/grub/menu.lst
34+
if [ -f /boot/grub/menu.lst ]; then
35+
# Not available in recent Ubuntu builds, so this is optional.
36+
sed -i.bak 's|^kernel.*$|\0 cgroup_enable=memory swapaccount=1|' /boot/grub/menu.lst
37+
fi
3338
sed -i -r 's|GRUB_CMDLINE_LINUX="(.*)"|GRUB_CMDLINE_LINUX="\1 cgroup_enable=memory swapaccount=1"|' /etc/default/grub
3439
update-grub
3540

@@ -45,7 +50,7 @@ systemctl restart docker
4550
usermod -G docker -a ubuntu
4651

4752
# Clone git repo
48-
mkdir /workshop
53+
mkdir -p /workshop
4954
pushd /workshop
5055
git clone https://github.com/Fewbytes/rubber-docker.git
5156
pip install -r rubber-docker/requirements.txt
@@ -101,4 +106,4 @@ echo "Installing plugins using Vundle"
101106
echo | echo | vim +PluginInstall +qall &>/dev/null
102107
echo "Vundle done"
103108
python ~/.vim/bundle/YouCompleteMe/install.py
104-
EOS
109+
EOS

packer/http/preseed.cfg

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
choose-mirror-bin mirror/http/proxy string
2+
d-i base-installer/kernel/override-image string linux-server
3+
d-i clock-setup/utc boolean true
4+
d-i clock-setup/utc-auto boolean true
5+
d-i finish-install/reboot_in_progress note
6+
d-i grub-installer/only_debian boolean true
7+
d-i grub-installer/with_other_os boolean true
8+
d-i partman-auto/disk string /dev/sda
9+
d-i partman-auto-lvm/guided_size string max
10+
d-i partman-auto/choose_recipe select atomic
11+
d-i partman-auto/method string lvm
12+
d-i partman-lvm/confirm boolean true
13+
d-i partman-lvm/confirm boolean true
14+
d-i partman-lvm/confirm_nooverwrite boolean true
15+
d-i partman-lvm/device_remove_lvm boolean true
16+
d-i partman/choose_partition select finish
17+
d-i partman/confirm boolean true
18+
d-i partman/confirm_nooverwrite boolean true
19+
d-i partman/confirm_write_new_label boolean true
20+
d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common
21+
d-i pkgsel/install-language-support boolean false
22+
d-i pkgsel/update-policy select none
23+
d-i pkgsel/upgrade select full-upgrade
24+
d-i time/zone string UTC
25+
tasksel tasksel/first multiselect standard, ubuntu-server
26+
27+
d-i console-setup/ask_detect boolean false
28+
d-i keyboard-configuration/layoutcode string us
29+
d-i keyboard-configuration/modelcode string pc105
30+
d-i debian-installer/locale string en_US
31+
32+
# Create ubuntu user account.
33+
d-i passwd/user-fullname string ubuntu
34+
d-i passwd/username string ubuntu
35+
d-i passwd/user-password password ubuntu
36+
d-i passwd/user-password-again password ubuntu
37+
d-i user-setup/allow-password-weak boolean true
38+
d-i user-setup/encrypt-home boolean false
39+
d-i passwd/user-default-groups ubuntu sudo
40+
d-i passwd/user-uid string 900
41+
42+
# Enable passwordless sudo for ubuntu so other config scripts can work.
43+
d-i preseed/late_command string \
44+
echo 'ubuntu ALL=(ALL) NOPASSWD: ALL' > /target/etc/sudoers.d/ubuntu ; \
45+
in-target chmod 440 /etc/sudoers.d/ubuntu ;

packer/rubber-docker-aws.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"variables": {
3+
"aws_access_key": "{{ env `AWS_ACCESS_KEY_ID` }}",
4+
"aws_secret_key": "{{ env `AWS_SECRET_ACCESS_KEY` }}",
5+
"aws_region": "eu-central-1",
6+
"source_ami": "ami-fe408091",
7+
"subnet_id": "subnet-24e10b4d"
8+
},
9+
"builders": [
10+
{
11+
"type": "amazon-ebs",
12+
"access_key": "{{ user `aws_access_key` }}",
13+
"secret_key": "{{ user `aws_secret_key` }}",
14+
"region": "{{ user `aws_region` }}",
15+
"source_ami": "{{ user `source_ami` }}",
16+
"instance_type": "t2.medium",
17+
"associate_public_ip_address": true,
18+
"subnet_id": "{{ user `subnet_id` }}",
19+
"ssh_username": "ubuntu",
20+
"ami_name": "rubber-docker-{{timestamp}}",
21+
"ami_groups": [
22+
"all"
23+
]
24+
}
25+
],
26+
"provisioners": [
27+
{
28+
"type": "file",
29+
"source": "vimrc",
30+
"destination": "/tmp/vimrc"
31+
},
32+
{
33+
"type": "shell",
34+
"script": "bootstrap.sh"
35+
}
36+
]
37+
}

packer/rubber-docker-vmware.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"builders": [
3+
{
4+
"type": "vmware-iso",
5+
"boot_command": [
6+
"<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
7+
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
8+
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
9+
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
10+
"/install/vmlinuz<wait>",
11+
" auto<wait>",
12+
" console-setup/ask_detect=false<wait>",
13+
" console-setup/layoutcode=us<wait>",
14+
" debconf/frontend=noninteractive<wait>",
15+
" debian-installer=en_US<wait>",
16+
" fb=false<wait>",
17+
" initrd=/install/initrd.gz<wait>",
18+
" keyboard-configuration/layout=USA<wait>",
19+
" keyboard-configuration/variant=USA<wait>",
20+
" locale=en_US<wait>",
21+
" netcfg/get_domain=vm<wait>",
22+
" netcfg/get_hostname=rubber-docker<wait>",
23+
" grub-installer/bootdev=/dev/sda<wait>",
24+
" noapic<wait>",
25+
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
26+
" -- <wait>",
27+
"<enter><wait>"
28+
],
29+
"boot_wait": "10s",
30+
"disk_size": 20480,
31+
"guest_os_type": "ubuntu-64",
32+
"headless": true,
33+
"http_directory": "http",
34+
"iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.4-server-amd64.iso",
35+
"iso_checksum_type": "sha256",
36+
"iso_checksum": "0a03608988cfd2e50567990dc8be96fb3c501e198e2e6efcb846d89efc7b89f2",
37+
"output_directory": "packer-rubber-docker-ubuntu-16.04-vmware",
38+
"shutdown_command": "echo 'ubuntu'|sudo -S shutdown -P now",
39+
"ssh_password": "ubuntu",
40+
"ssh_port": 22,
41+
"ssh_username": "ubuntu",
42+
"ssh_wait_timeout": "10000s",
43+
"tools_upload_flavor": "linux",
44+
"vm_name": "rubber-docker-ubuntu-16.04",
45+
"vmx_data": {
46+
"cpuid.coresPerSocket": "1",
47+
"memsize": "1024",
48+
"numvcpus": "1"
49+
}
50+
}
51+
],
52+
"provisioners": [
53+
{
54+
"type": "file",
55+
"source": "vimrc",
56+
"destination": "/tmp/vimrc"
57+
},
58+
{
59+
"type": "shell",
60+
"script": "bootstrap.sh"
61+
}
62+
]
63+
}

0 commit comments

Comments
 (0)