Using Vagrant
December 10, 2014

Using Vagrant

Posted on December 10, 2014

In 2013, I finally made the switch over to a Mac. Before that, I was content with Ubuntu Linux. I was so devoted to Linux, I was even using the Gimp as my pixel editor and Inkscape for vector art. I even had tried the wacky idea of getting a Mac laptop duo-booting with Ubuntu. When I got used to Mac’s Unix, most bash commands are the same and files, beside the home directory are in the same place. Now it seemed a waste to have a duo-boot, and I had already been using VirtualBox on Ubuntu, so I did the same on the Mac.

Vagrant is configured from on file. Configure the Vagrantfile, then you can issue a simple vagrant up command to initiate or run a VirtualBox instance.

Sample Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Ubuntu-13.10
  config.vm.box = "Ubuntu-13.10"
  config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-13.10_chef-provisionerless.box"
  config.vm.synced_folder "../.", "/home/vagrant/portal-up"  
  config.ssh.forward_x11 = true
  config.vm.network "forwarded_port", guest: 8000, host: 8000, auto_correct: true
  config.vm.network "forwarded_port", guest: 5432, host: 5432, auto_correct: true
  config.vm.network "private_network", ip: "192.168.10.2"
  config.vm.provider :virtualbox do |virtualbox|
    virtualbox.customize ["modifyvm", :id, "--name", "main-gobox"] # Name the INSTANCE (app), make unique
    virtualbox.customize ["modifyvm", :id, "--memory", "1024"]
  end
  config.vm.provision :shell, :path => "ubuntu-13.10-64-install.sh"  
end

Only on the first run, Vagrant will use the config.vm.box_url setting to load an OS image. You can find other images at http://www.vagrantbox.es/. This makes it easy to have a template OS or recover from a backup. After the instance has been created, it uses config.vm.provision to launch a Bash script to install and configure software not included in the VirtualBox image. See ubuntu-13.10-64-install.sh.

Common Commands

vagrant up
vagrant halt
vagrant destroy
vagrant ssh

The biggest benefit with Vagrant is the configuration files can be save in the code repository. This made replication of the workspace available and backuped.

Bonus, I was able to return to Photoshop and Illustrator.

Links

  • https://www.vagrantup.com/
  • https://www.virtualbox.org/
  • https://github.com/kyledinh/verkbox (updated)