There are many challenges associated with building applications in the cloud. One of the most challenging is that the cloud properly exploited is inherently transient. This means that your development environment must also be transient, such that you never depend on unfounded assumptions. Once upon a time you would routinely re-install your OS to ensure you weren’t mistakenly assuming something were present. Moving development to a VM with a snapshot made this even faster. Vagrant took things even further, allowing users to essentially emulate a cloud instance in their own systems. Just run “vagrant up” and in minutes or even seconds, you have a local instance, fresh and new, ready to work in and it even mounts your local directory into the VM to make things all that much easier. The result, much less time spinning up and down instances in a public cloud doing development and faster iteration in a highly controlled environment.
Vagrant has blossomed into a solution for the “OS Lab”. Once upon a time if you were developing applications and wanted to build and test it for multiple platforms you would maintain a lab full of systems with different hardware, OS’s and OS versions. But not that nearly every modern OS is on X86, we can replace a room full of servers with a handful of Vagrant boxes which run on your workstation or laptop. Vagrant pushes all the complexity of managing a large number of very different VM types aside and offers you with a single easy to use and very fast interface.
And so it stands to reason that a system as unique and powerful as SmartOS should be a part of this world. Many have tried to create Vagrant boxes for SmartOS, but none have been as powerful and beautifully integrated as those of our good friend Andrzej Szeszo. You can find his goodies here, including his build scripts and tools. He just updated them today and I really hope that people will use them and provide him feedback to encourage him to keep making them.
What truly sets Andrzej’s boxes apart is that your not actually working with SmartOS itself but rather with SmartMachines (Zones). This is what you really want, the SmartOS GZ isn’t where your going to deploy anything but operational utilities for monitoring VMs… its within the Zones that you’ll do your real work and Andrzej offers a variety of boxes for a variety of SmartMachine templates and makes the Vagrant experience transparently traverse the SmartOS Global Zone directly into a Zone.
Getting started with Vagrant and these SmartOS boxes is easy. First, download the latest version of Vagrant from vagrantup.com and install it. Secondly, install or update either VMWare or Virtualbox to the latest version (or something reasonably recent). With those preliminaries out of the way, create a new directory (for instance, ~/vagrant/smartos-base64-13.1.0), enter it, run “vagrant init” and then make the generated Vagrant file look like this:
Vagrant.configure("2") do |config| config.vm.box = "smartos-base1310-64-virtualbox-20130806.box" config.vm.box_url = "http://dlc-int.openindiana.org/aszeszo/vagrant/smartos-base1310-64-virtualbox-20130806.box" end
This Vagrantfile above simply supplies a name for our Vagrant box (a box is a VM template) and then a URL from which to download the box if its not already installed. If you want a different Vagrant box, just adjust the above accordingly.
Now start the VM using “vagrant up”. Because we don’t already have the box specified, it will be downloaded. Here is what it looks like:
benr@magnolia:~/vagrant/base64-13.1.0$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... [default] Box 'smartos-base1310-64-virtualbox-20130806.box' was not found. Fetching box from specified URL for the provider 'virtualbox'. Note that if the URL does not have a box for this provider, you should interrupt Vagrant now and add the box yourself. Otherwise Vagrant will attempt to download the full box prior to discovering this error. Downloading with Vagrant::Downloaders::HTTP... Downloading box: http://dlc-int.openindiana.org/aszeszo/vagrant/smartos-base1310-64-virtualbox-20130806.box Extracting box... Cleaning up downloaded box... Successfully added box 'smartos-base1310-64-virtualbox-20130806.box' with provider 'virtualbox'! [default] Importing base box 'smartos-base1310-64-virtualbox-20130806.box'... [default] No guest additions were detected on the base box for this VM! Guest additions are required for forwarded ports, shared folders, host only networking, and more. If SSH fails on this machine, please install the guest additions and repackage the box to continue. This is not an error message; everything may continue to work properly, in which case you may ignore this message. [default] Matching MAC address for NAT networking... [default] Setting the name of the VM... [default] Clearing any previously set forwarded ports... [default] Fixed port collision for 22 => 2222. Now on port 2200. [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Preparing network interfaces based on configuration... [default] Forwarding ports... [default] -- 22 => 2200 (adapter 1) [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use! [default] Configuring and enabling network interfaces... [default] Mounting shared folders... [default] -- /vagrant
And now that its up, lets SSH into it:
benr@magnolia:~/vagrant/base64-13.1.0$ vagrant ssh Last login: Wed Aug 7 06:42:16 2013 from 10.0.2.2 __ . . _| |_ | .-. . . .-. :--. |- |_ _| ;| || |(.-' | | | |__| `--' `-' `;-| `-' ' ' `-' / ; SmartMachine (base64 13.1.0) `-' http://wiki.joyent.com/jpc2/SmartMachine+Base [vagrant@smartos-base1310-64 ~]$ [vagrant@smartos-base1310-64 ~]$ df -h Filesystem Size Used Avail Use% Mounted on zones/zone 35G 379M 35G 2% / ... vagrant-root 219G 83G 137G 38% /vagrant
You’ll notice that /vagrant is actually mounting your vagrant directory, which makes transferring data in and out quick and easy and allows for persistence.
When your done with your VM, “vagrant destroy” and its gone. Please do remember, you can run multiple VMs, the commands you run determine which one your referring to based on your directly and Vagrantfile.
I hope this gives you a quick glimpse of what Vagrant is all about and if your experienced with it gives you an interest in trying SmartOS SmartMachines (Zones). To learn much more about Vagrant go to vagrantup.com.