# OpenDaylight Packer
-[Packer][1] is a tool for automatically creating well-defined machine
-images of various types and optionally post-processing them into
-Vagrant base boxes, among other options.
+[Packer][1] is a tool for automatically creating VM and container images,
+configuring them and post-processing them into standard output formats.
-OpenDaylight's current use-case for Packer is to build an ODL Vagrant
-base box, provisioned using upstream deployment/config tools. Reusing
-the logic of our configuration management tools nicely standardizes our
-deployment story, enabling good code reuse and separation of
-responsibilities. Providing an upstream Vagrant base box prevents all
-ODL consumers from duplicating ODL download, install and configuration
-logic, data transfer and computation in every Vagrantfile we create.
-
-We currently only support CentOS 7, output as a VirtualBox machine image,
-packaged into a Vagrant box. Additional development is ongoing.
+We currently build OpenDaylight's Vagrant base box and Docker image via Packer.
## Building an ODL Vagrant Base Box
a VirtualBox host.
* Run a post-install shell provisioner to do VirtualBox, Vagrant
and Ansible-specific config.
-* Install OpenDaylight using its [Ansbile role][4].
+* Install OpenDaylight using its [Ansible role][4].
* Export, compress and package the VM as a Vagrant base box.
```
{
"variables": {
- "box_version": null
+ "box_version": null,
+ "docker_version": null,
+ "docker_name": null
},
"builders": [
{
"headless": "false",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
+ "ssh_wait_timeout": "20m",
"shutdown_command": "sudo shutdown -P now",
"http_directory": ".",
"boot_command": [
"2"
]
]
+ },
+ {
+ "type": "docker",
+ "image": "centos:7.1.1503",
+ "pull": false,
+ "commit": true
}
],
"provisioners": [
"type": "shell",
"scripts":
[
- "config_vagrant.sh",
"config_virtualbox.sh",
+ "config_vagrant.sh",
"config_ansible.sh"
+ ],
+ "only":
+ [
+ "virtualbox-iso"
+ ]
+ },
+ {
+ "type": "shell",
+ "scripts":
+ [
+ "config_docker.sh",
+ "config_ansible.sh"
+ ],
+ "only":
+ [
+ "docker"
]
},
{
{
"type": "vagrant",
"compression_level": "9",
- "output": "opendaylight-{{ user `box_version` }}-centos-1503.box"
+ "output": "opendaylight-{{ user `box_version` }}-centos-1503.box",
+ "only": ["virtualbox-iso"]
+ },
+ {
+ "type": "docker-tag",
+ "repository": "{{ user `docker_name` }}",
+ "tag": "{{ user `docker_version` }}",
+ "force": true,
+ "only": ["docker"]
}
]
}
%packages
# Install minimal set of packages here, let provisioners (Ansible) handle them
- @Base
- @Core
%end
%post
useradd vagrant -g vagrant -G wheel
echo "vagrant" | passwd --stdin vagrant
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
+
+ # Everything requires the ability to run sudo without a tty
+ # Else, may see errors like "sorry, you must have a tty to run sudo"
+ # Need to do this here, before Packer reboots the VM and runs scripts,
+ # because `sudo` in the scripts fails without it. Docker also needs this
+ # (for Ansible to run `sudo`), but it doesn't run this kickstart, so it the
+ # logic must be duplicated in Docker's config script and here.
+ sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
%end
sudo yum install -y epel-release
# Install Ansible, required for Packer's ansible-local provisioner
-sudo yum install -y ansible
+# Git is required by the ansible-galaxy tool when installing roles
+sudo yum install -y ansible git
# Install the latest release of ODL's Ansible role from Ansible Galaxy
# The `ansible-galaxy` tool was installed by Ansible's RPM
# push what's version controlled, and we can't install the role
# pre-build manually on the remote host, so we have to let Packer
# own the ODL role install.
-sudo ansible-galaxy install dfarrell07.opendaylight
+# NB: The simple `ansible-galaxy install <role>[,version]` syntax doesn't
+# support versions other than those on Ansible Galaxy, so tags. The
+# `ansible-galaxy` command will accept more complex versions via a
+# requirements.yml file, however. Using that to support branches,
+# commits, and tags. See: http://stackoverflow.com/a/30176625/1011749
+# TODO: Pass this version var from packer_vars.json
+ansible_version="origin/master"
+cat > /tmp/requirements.yml << EOM
+- name: opendaylight
+ src: https://github.com/dfarrell07/ansible-opendaylight
+ version: $ansible_version
+EOM
+sudo ansible-galaxy install -r /tmp/requirements.yml
# Clean up to save space
+# NB: The point of this script is to leave Ansible and ODL's role installed
+# and ready for use by the Packer Ansible provisioner, so we can't clean
+# up that space here. Need to clean it up in a post-install cleanup script.
+sudo yum remove -y git
sudo yum clean all -y
sudo rm -rf /tmp/*
--- /dev/null
+#!/usr/bin/env bash
+# Called by packer to do any Docker-specific config
+
+# Echo commands as they are run
+set -x
+
+# Install minimal set of packages
+# Need to do this as root but don't have sudo installed (Docker), so `su -c`
+# The `sudo` program is needed by Ansible (so can't change it to use `su -c`)
+# TODO: Is all of @Base strictly necessary?
+su -c "yum install -y @Base sudo"
+
+# Docker uses Ansible to configure ODL, and Ansible uses `sudo` so Docker's
+# build will fail at Ansible without this config change (even if we removed it
+# from subsequent Docker shell provisioning scripts).
+su -c 'sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers'
curl -o /home/vagrant/.ssh/authorized_keys -kL "https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub"
chmod 600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
-
-# Vagrant requires the ability to run sudo without a tty
-# Else, `vagrant up` will fail with: "sorry, you must have a tty to run sudo"
-sudo sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
set -x
# Install utilities required by VB Guest Additions install
-sudo yum install -y bzip2 gcc kernel-devel
+# TODO: Is all of @Base and @Core strictly required?
+sudo yum install -y @Base @Core bzip2 gcc kernel-devel
# Install VirtualBox Guest Additions (downloaded by Packer)
sudo mount -o loop /home/vagrant/VBoxGuestAdditions.iso /mnt
- hosts: localhost
sudo: yes
roles:
- - dfarrell07.opendaylight
+ - opendaylight
{
- "box_version": "2.3.0"
+ "box_version": "3.0.0",
+ "docker_version": "3.0.0",
+ "docker_name": "opendaylight/odl"
}