Add Li Docker image, update Vagrant base box to Li
authorDaniel Farrell <dfarrell@redhat.com>
Thu, 2 Jul 2015 18:38:25 +0000 (14:38 -0400)
committerDaniel Farrell <dfarrell@redhat.com>
Fri, 14 Aug 2015 15:11:01 +0000 (15:11 +0000)
Builds/configures ODL Docker images via the same pipeline used by
Packer when creating Vagrant base boxes.

Upgrades the Vagrant base box to Lithium, mostly for free via updates
to the Ansible role.

Starts with a recent, fresh CentOS 7 image, does low-level provisioning
via Kickstart, then Packer scripts, then ODL's Ansible role, which uses
ODL's CBS RPM. The result is post-processed into a Vagrant box and a
Docker image.

I did a bit of a docs update, but I need to revisit Packer's docs in
general and do more.

Change-Id: I123e416573ab079c9350998c4f4deed8d02f7568
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
packaging/packer/README.markdown
packaging/packer/centos.json
packaging/packer/centos_kickstart.cfg
packaging/packer/config_ansible.sh
packaging/packer/config_docker.sh [new file with mode: 0644]
packaging/packer/config_vagrant.sh
packaging/packer/config_virtualbox.sh
packaging/packer/install_odl.yml
packaging/packer/packer_vars.json

index aebdaa657d081354338dd0d58600687d4b0f12f2..161524c00541f14ceed45438c2ecbab268defeed 100644 (file)
@@ -1,19 +1,9 @@
 # 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
 
@@ -32,7 +22,7 @@ This will:
   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.
 
 ```
index 21f2fb14c4d97980cefa90c84b32a71829d74aad..cd2f42069b69fc86a5578e6e8915725e7f408beb 100644 (file)
@@ -1,6 +1,8 @@
 {
   "variables": {
-    "box_version": null
+    "box_version": null,
+    "docker_version": null,
+    "docker_name": null
   },
   "builders": [
     {
@@ -19,6 +21,7 @@
       "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"]
     }
   ]
 }
index 96680644482fdcdd4c622984a8338ba662ce2591..5f2e0a7e076a7d26bd08d354d506a03bdabb85ac 100644 (file)
@@ -39,8 +39,6 @@ reboot
 
 %packages
   # Install minimal set of packages here, let provisioners (Ansible) handle them
-  @Base
-  @Core
 %end
 
 %post
@@ -64,4 +62,12 @@ reboot
   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
index 527a2f0db8cda92e0eaaa00e444f776b023f63ba..20796323851e9aff45eae34bd8982cd0520b8169 100644 (file)
@@ -10,7 +10,8 @@ set -x
 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
@@ -24,8 +25,24 @@ sudo yum install -y ansible
 #     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/*
diff --git a/packaging/packer/config_docker.sh b/packaging/packer/config_docker.sh
new file mode 100644 (file)
index 0000000..0f448bd
--- /dev/null
@@ -0,0 +1,16 @@
+#!/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'
index edfed44b7dfa35fa8b3e572f16cd1a0b70b8bc37..557fac6bd8089f5ef1f1ed2599dc63c359aaca32 100644 (file)
@@ -9,7 +9,3 @@ install -v -o vagrant -g vagrant -m 0700 -d /home/vagrant/.ssh
 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
index 8f56953a66e9f79f0c1e470c782a56942f111916..44282732235e2a7e5fdc79f1e74244d38017e271 100644 (file)
@@ -6,7 +6,8 @@
 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
index 14a4600bcecd309d622c01b3f1e67ea0e8ba3458..6f36f75b8f556e17110652223c3bfd31041628db 100644 (file)
@@ -2,4 +2,4 @@
 - hosts: localhost
   sudo: yes
   roles:
-    - dfarrell07.opendaylight
+    - opendaylight
index 2bfed16049e120a70e83ede244cbd59db74e51cb..8a5fa2bf65c082ce8772a6d92b40aaef5ba27a2c 100644 (file)
@@ -1,3 +1,5 @@
 {
-  "box_version": "2.3.0"
+  "box_version": "3.0.0",
+  "docker_version": "3.0.0",
+  "docker_name": "opendaylight/odl"
 }