« Previous 1 2 3 4 Next »
Vagrant, Serf, Packer, and Consul create and manage development environments
Strong Quad
Assembly Service
When you first start the virtual machine, Vagrant can run arbitrary commands and programs automatically (e.g., to install and set up a web server retroactively using a shell script), and it makes provisioning a quick and easy process. Vagrant not only runs shell scripts, it also works with the configuration systems Chef, Puppet, Ansible, Salt, and CFEngine. On request, the tool even creates Docker containers. Plugins let you retrofit more of these provisioners.
By default, Vagrant passes the developer's directory through to the guest machine, where it appears in the /vagrant
directory. Similarly, the tool can synchronize any directory on the hard disk with any on the virtual machine (synced folders). In this way, the developer sees the effects of changes directly in the filesystem.
Vagrant is not just available for Linux, but also for Windows and Mac OS X. Prebuilt binary packages in the Debian and RPM format are available from the project homepage. Additionally, the tool is available from the repositories of various distributions. Ubuntu only has the slightly older version 1.4.3. Vagrant itself is written in Ruby; installing as a Rubygem is no longer intended in the current versions of Vagrant. The tool is available under the liberal MIT license, and the open source code is on GitHub [6].
Packer
Normally, it is a good idea to provide the complete application as a virtual machine (appliance). If customers use different virtualization solutions, though, this can quickly become a huge amount of work. Here is where Packer steps in [7]. The tool not only sets up a virtual machine automatically, it also builds images for cloud services such as Amazon EC2, DigitalOcean, Google Compute Engine, and OpenStack, as well as the virtualization solutions VirtualBox, VMware, Qemu (for KVM and Xen), Parallels, and Docker. On request, Packer also creates a box for Vagrant. Plugins let you add support for additional platforms. Packer can also draw on Chef and Puppet to set up the guest system.
In contrast to Vagrant, HashiCorp provides the Packer program as a distribution-independent ZIP archive, with versions for 32-bit, 64-bit, and ARM systems. Besides Linux, Packer runs on Windows, Max OS X, FreeBSD, and OpenBSD. You have to install the tool manually by moving the content of the ZIP archive to a suitable directory (e.g., /usr/local/bin
on Linux). The source code is written in the Go programming language, lives on GitHub [8], and is subject to the Mozilla public license version 2.0.
Bindlestiff
Developers use a configuration file in JSON format to describe the desired output format and content of the virtual machine. Listing 2 shows an example of a template. The first of the two sections defines how Packer should create the image(s). A builder tool that specializes in a specific output format handles the image-building process. The third line in Listing 2 enables a builder called virtualbox-ovf
. It first picks up an existing image in the OVF interchange format, the one in Listing 2 goes by the name of debian7.ovf
. From this, the builder creates a copy, which it then starts with VirtualBox (Figure 3).
Listing 2
Simple Template for Packer
01 { 02 "builders": [{ 03 "type": "virtualbox-ovf", 04 "source_path": "debian7.ovf", 05 "ssh_username": "root", 06 "ssh_password": "123456", 07 "ssh_wait_timeout": "30s", 08 "shutdown_command": "echo 'Done' | sudo -S shutdown -h now" 09 }], 10 "provisioners": [{ 11 "type": "shell", 12 "inline": [ 13 "sleep 30", 14 "sudo apt-get update", 15 "sudo apt-get install -y sqlite3" 16 ] 17 }] 18 }
The subsequent configuration of the guest system is handled by provisioners in Vagrant. Listing 2 starts the shell provisioner, which executes the commands in the Lines 13 to 15. This, in turn, installs SQLite on the guest system. You can then log in via SSH with a username of root
and a password of 123456
. Listing 2 has this information in lines five and six. Packer uses shutdown_command
to tell the virtual machine to shut down.
Finally, builder steps in again and exports the guest system to OVF format. In addition to virtualbox-ovf
Packer has a number of other builders. For example, virtualbox-iso
draws on VirtualBox to install a completely new virtual machine and install a fresh system on it. The source is an ISO image that it downloads from a server; it even checks the checksum in the process. Of course, this process only works if the complete installation can be handled without user input. If you like, you can retroactively install your own builders and provisioners via the plugin system.
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)