Vagrant: Better way to work in team

Problems: How to…

  • isolate the development environment?
  • share the development environment?
  • deal with dependency?

Some excuses

  • Works on my machine
  • You must have done something wrong
  • I did a quick fix last time but it broke when we rebooted
  • ……

A possible answer…

Virtualization

Too bloated and hard to use in practice :(

What we want:

$ git clone git://myrepo

$ [some magic command]
$ [or maybe another command]

// now you get an isolated environment to make something big

What vagrant do?

Using virtualization to share the environment, but easy to use!

Benefits

  • Environment per project
  • Versionable
  • Shared across the team
  • No more: "Works on my machine!"

How to use

Create and run a VM

$ vagrant init ubuntu/trusty64
$ vagrant up
$ vim Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.box_url = 'http://box.hosts.com/trusty64.box'
end

Enter the development env

$ vagrant ssh
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-44-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Apr 17 11:27:38 UTC 2015

  System load:  0.44              Processes:           87
  Usage of /:   5.5% of 39.34GB   Users logged in:     0
  Memory usage: 12%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud


Last login: Thu Mar 26 15:02:03 2015 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty-64:~$

Synced folders

$ vagrant up
...

$ vagrant ssh
...

vagrant@precise32:~$ ls /vagrant
Vagrantfile
vagrant@precise32:~$ touch /vagrant/foo
vagrant@precise32:~$ exit

$ ls
foo Vagrantfile

Port Forwarding

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network :forwarded_port, host: 4567, guest: 80
end

Provision

$ vim bootstrap.sh

#!/usr/bin/env bash

apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  rm -rf /var/www
  ln -fs /vagrant /var/www
fi
$ vi Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provision :shell, path: "bootstrap.sh"
end

Other commands

$ vagrant suspend
// save the current running state of the machine and stop it
// run `vagrant up` to resume

$ vagrant halt
// shutdown and poweroff the vm

$ vagrant destory
// delete the vm from your computer

Provider

  • Virtualbox
  • VMWare
  • Docker
  • KVM
  • Hyper-V
  • AWS

Workflow

$ git clone git://...
$ vagrant up
$ vagrant ssh
(new environment in vm)
$ gulp
// run gulp to auto build your website

Thank you! 😃

Vagrant: Better way to work in team

By Jiajun Wang

Vagrant: Better way to work in team

  • 172