Using Packer to create a development virtual machine for GeoBlacklight
Jan 23, 2016
When we run the GeoBlacklight workshop, we provide attendees with a VirtualBox virtual machine (vm) so that they can participate without having download software. Having attendees connect to the internet to download large files doesn’t always work in conference environments. To keep up to date with software dependencies we have rebuilt this virtual machine several times. Recently, the process for creating and updating the virtual machine has been automated using Packer. From Packer’s website:
Packer is a tool for creating machine and container images for multiple platforms from a single source configuration.
This tutorial outlines how we create the GeoBlacklight workshop vm, so that others can create this virtual machine from scratch. This tutorial could also be adapted to create an image for Amazon EC2, Digital Ocean, Docker, and others.
To get started, you will need to install several pieces of software that our Packer template will use. Go ahead and install this software for your system.
Once you have installed all of the software, make sure that you have Packer available on your path.
$ packer -v 0.8.6
Using the GeoBlacklight Packer template
$ git clone https://github.com/mejackreed/packer-templates.git
Next change directory (
cd) into the git repository you just cloned.
$ cd packer-templates
And checkout the
$ git checkout geoblacklight
Finally, change directory (
cd) into the
ubuntu-16.04.3 directory. This is the image I based the GeoBlacklight Workshop image on.
$ cd ubuntu-16.04.3
It should be noted that I opted for the 32-bit version of this release of Ubuntu for maximum compatibility. You may want to change the version of Ubuntu used and thus you must also update the checksum.
Exploring the Packer template
template.json file is where Packer takes its directions from. I won’t go through everything in this file, but I will point out some of the customizations I made for the GeoBlacklight workshop.
The major customizations added, were the addition of four scripts that run during creation.
Installs rbenv, Ruby, bundler, and specifies no rdoc documentation.
Installs nodejs and Ruby on Rails.
Creates a GeoBlacklight application and downloads and configures jetty/solr.
Creating the Vagrant box
You can modify any of these scripts to meet your customization needs. After doing so, you will want to create your VirtualBox vm. To do so run the following command from the
$ packer build template.json
This command will take a while so it might be best to go get a coffee. What the command is doing:
- Downloading a fresh copy of Ubuntu
- Creating a VirtualBox image with that copy of Ubuntu
- Updating the vm’s packages
- Installing our custom software
After the command finishes you should have your virtual machine box waiting for you in the same directory.
To create a
Vagrantfile to use with this box:
$ vagrant init ubuntu-14-04-3-x32-virtualbox.box
Now you can start up your fresh box using:
$ vagrant up
And to ssh in
$ vagrant ssh
I hope this tutorial is useful to others who run technical workshops. It can sometimes be painful in trying to support workshops on multiple platforms with limited network connectivity. This workflow of using Packer, Vagrant, and VirtualBox has been successful for us.