Give your development a portable home with Vagrant

Who Am I?

Gavin Mogan
@halkeye
https://www.gavinmogan.com
Gavin Mogan
Been using computers before it was cool
(okay not really)

So what am I talking about?

Vagrant chilling
No not that kind of vagrant

What is Vagrant?

Vagrant is a simple tool that makes it easy to setup Virtual Machines

Its a pretty powerful tool.

Only covering the basics

And why should I care?

  • Documentation
    • Always out of date.
  • Mentoring
    • People often forget things they have not used in a while.
  • Onboarding
    • Pretty much the previous two combined.
  • Don't want to wait to get started.
Story time

I mean Contrived Example Time!

Sam

Sam - Developer

  • Has been working on the project "forever"
  • Lots of linux experience
  • Likes to tinker with the build process

"Sam" by Heather L. Gilbraith

Alex

Alex - Designer

  • Wants project to just work
  • Wants focus on getting work done
  • Often frustrated with Sam

"Alex" by Heather L. Gilbraith

You

You - ???

  • New to the project
  • Different Location?
  • Often frustrated with Sam

Scene!

  1. Sam adds a new image compression tool to the builds
  2. Sam pushes the code
  3. Sam forgot to update the documentation to include instructions
    • Windows - Good luck
    • Linux - apt-get install libpng-dev
    • OSX - brew install libpng
  4. Alex pulls down new code
  5. Alex's build brakes, and is now blocked. Yells for Sam
  6. FIGHT!
Fight

Now with vagrant!

  1. Sam adds a new image compression tool to the builds
  2. Sam adds "apt-get install libpng-dev" to Vagrantfile
  3. Alex pulls down new code
  4. Alex runs vagrant provision
  5. Alex keeps working
Happy

Real Life Example

jQuery Documentation Site

jQuery docs

So what is vagrant?

  • A way to quickly setup a consistent environment
  • It doesn't care what you are running, its only job is to setup a working environment
  • Re-creatable
  • Great tool for getting everyone to have a consistent environment

Did I mention consistent?

Consistent

How does it work?

  • Uses virtual machine software, at this point almost everything is available
    • Virtual Box, VMWare, Hyper-V (windows), Docker, Probably more
  • Downloads a VM image
  • Applies steps
  • Success!
  • Profit
Profit

No really, How does it work?

  1. Install your favourite Virtual Machine System
    • I suggest virtualbox
    • Don't install (or at least don't run) multiple
  2. Install Vagrant
  3. Launch terminal/command prompt
  4. Change to project directory
  5. vagrant init ubuntu/trusty64
  6. vagrant up
  7. vagrant ssh
Vagrant screenshot

Well that's not super useful.

Now what?

  • Config file (Vagrantfile) is really well documented
  • Can setup port forwards
  • Shared directories
  • Provisioning
    • Simple Shell scripts
    • Puppet
    • Chef
    • Ansible
    • More

Bonus


            # Vagrantfile

            # Real file is super commented

            Vagrant.configure(2) do |config|
            config.vm.box = "ubuntu/trusty64"

            # stuff
            config.vm.provision "shell", inline: <<-SHELL
            sudo apt-get update
            sudo apt-get install -y libpng-dev
            SHELL
            end
          

Thanks!

Gavin Mogan

@halkeye

https://www.gavinmogan.com

Gavin Mogan

YVR Developers Slack - https://yvrdev.herokuapp.com/