Lead Image © 36clicks, 123RF.com

Lead Image © 36clicks, 123RF.com

Vagrant, Serf, Packer, and Consul create and manage development environments

Strong Quad

Article from ADMIN 22/2014
By
Four open source tools – Vagrant, Serf, Packer, and Consul – facilitate a developer's work by each handling one specific task elegantly.

Programmers often try to set up a development environment for their projects that matches the production environment. However, upon starting up the finished software, they might discover some required libraries are missing or a slightly modified configuration leads to unexpected side effects. Vagrant [1] prevents this kind of situation. The tool creates a virtual machine with a suitable development environment at the push of a button. The machines produced in this way are not only portable, but Vagrant can always reproduce them precisely. Finished machines can also be passed on to other team members and relocated to the production environment, if needed.

On the Rails

Mitchell Hashimoto began to develop Vagrant in his spare time, but because of the fast-growing numbers of users, he founded the one-man company HashiCorp in the fall of 2012, so he could work full-time on Vagrant. The company primarily earned money through support contracts, training, and the development of commercial add-ons. According to HashiCorp, current users of Vagrant are the BBC, O'Reilly, and Expedia, in addition to Mozilla and Disqus.

To set up a development environment with Vagrant, you first create a small configuration file in your project directory. Within this file, called Vagrantfile (case not important), you need to describe the required software, configure the virtual machine, and determine how you would like to access the guest system. A PHP programmer might want a Debian system with a web server, for example.

Vagrant even works as a wrapper for the virtualization software or provider. Vagrant natively supports VirtualBox, Docker, and Microsoft's Hyper-V. You can add more providers in the form of plugins. If you want to run Vagrant with VMware, you will find a suitable plugin on the HashiCorp site [2]. As a commercial product, this costs around US$ 80 per license.

Cloudy Boxes

To start the virtual machine as quickly as possible, Vagrant just clones a complete disk image and then modifies it. Vagrant calls these base images "boxes." Prebuilt boxes can be downloaded free of charge via the community collection on Vagrantbox.es [3] (Figure 1) or from the Vagrant Cloud powered by HashiCorp [4]. The latter provides a virtual machine with Debian 7.4 and Chef pre-installed.

Figure 1: Vagrantbox.es provides links to publicly accessible Vagrant boxes. Their use requires a great deal of trust in the creator.

If you register for free in the Vagrant Cloud, you can also take advantage of the Vagrant Share service. It offers a kind of dynamic DNS service for boxes: At the command line, the Vagrant user can combine a running virtual machine with a new subdomain on Vagrantshare.com. Its development environment is subsequently accessible on the Internet (e.g., on http://hulking-chameleon-3934.vagrantshare.com ). In this way, you can test logging into the new web application with OAuth under real conditions and give team members in branch offices an insight into ongoing development.

If you want your boxes in the Vagrant Cloud to be accessible to certain people only, you need a paid subscription. Prices start at US$ 6 per month [5]; on top of that, each box download costs 12 cents (Figure 2). If you don't trust Vagrant Cloud, you can create your own boxes.

Figure 2: Vagrant Cloud offers convenient free services for boxes – and commercial extras.

Ruby Control

The configuration lines in Vagrantfile are Ruby code, but users do not need to know all about the scripting language. Listing 1 shows an example of a minimal configuration file: The second line uses

Listing 1

Example of a simple Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network :forwarded_port, host: 9999, guest: 80
end
config.vm.box = "ubuntu/trusty64"

to stipulate that a box in the Vagrant Cloud should run an Ubuntu 14.04 server in the 64-bit variant. The third line also sets up port forwarding, making the web server on the guest accessible on port 9999 of the host computer.

Once you have adapted the Vagrantfile to suit your needs, a vagrant up command is all it takes to have a working virtual machine. Typing vagrant ssh opens an SSH connection to the guest system.

If you have ever set up a virtual machine manually, including SSH access, you will probably be jumping for joy right now. As an added bonus, you can simply pass on the configuration file to other team members.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=