Give your development a portable home with Vagrant

Who Am I?

Been using computers before it was cool

(okay not really)

So what am I talking about?

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 tools.

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.

I mean Contrived Example Time!

Sam - Developer

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

Alex - Designer

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

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!

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​

Real Life Example

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?

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

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

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!

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

Vagrant

By Gavin Mogan

Vagrant

Come see me give the talk at code coffee meetup - Sept 17th - http://www.meetup.com/Code-Coffee-Vancouver/events/224950040/

  • 1,037
Loading comments...

More from Gavin Mogan