Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Faster VMs with Vagrant and Chef

DZone's Guide to

Faster VMs with Vagrant and Chef

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

Written by David Green for the Tasktop Blog.

Developing and testing changes in an environment that is the same as the deployment environment is one of the magic ingredients of the DevOps way. For engineers at Tasktop working on the Integration Factory, provisioning a new VM can occur multiple times in a day, so any inefficiencies in the process are painful. I recently stumbled across vagrant-cachier which reduces network usage and speeds up local Vagrant-based provisioning, drastically improving VM provisioning times.

Install vagrant-cachier as follows:

$ vagrant plugin install vagrant-cachier

Then add the following to your ~/.vagrant.d/Vagrantfile

Vagrant.configure("2") do |config|
  if Vagrant.has_plugin?("vagrant-cachier")
    config.cache.scope = :box
  end
end

That’s all! The next time you provision a VM using Vagrant, you should see a local cache being created under ~/.vagrant.d/cache

As you can see, vagrant-cachier creates a local cache of dependencies including those provided by apt-get, chef, and of course anything under /var/cache.
This technique is especially helpful for remote developers who are not on 100GB Ethernet to servers hosting VM dependencies.

It’s easy to try it yourself and collect before/after results. Here’s what I observed before vagrant-cachier:

$ time vagrant up 
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'ubuntu-14.04-x86'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
...
real	4m44.142s
user	0m4.895s
sys	0m3.132s
$ 

After enabling vagrant-cachier:

$ time vagrant up 
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'ubuntu-14.04-x86'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
...
real	3m18.506s
user	0m7.617s
sys	0m5.261s
$ 

In this real-world example of a simple VM running MySQL downloading dependencies over a VPN, I was able to reduce the provisioning time by 30%! The effect in real time is larger of course for VMs that have more dependencies.

Many thanks to @fgrehm for vagrant-cachier, which helps to eliminate much of the pain of waiting for VMs to come up when using Vagrant and Chef.
Find out more at http://fgrehm.viewdocs.io/vagrant-cachier.

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

Topics:

Published at DZone with permission of David Shepherd, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}