Vagrant Up!



Vagrant Up!

0 1


presentation-vagrant-up

Presentation for Twin Cities Code Camp 16 entitled Vagrant Up

On Github kyleboon / presentation-vagrant-up

Vagrant Up!

Kyle Boon

Kyle Boon

Senior Software Engineer @SmartThings
kyle.f.boon@gmail.com
@kyleboon
http://www.kyleboon.org

Vagrant creates Virtual clouds for your workstation. It's opensource and multi-platform

It works on my machine

-- every developer

Are you a full stack developer?

Wraps different virtual machine providers with a single command to create, provision and destroy machines.

Your first Vagrant image

$ vagrant init precise64
$ vagrant up

Main Concepts

  • Boxes
  • Vagrantfile
  • command line tool

Boxes

  • Template used to start a virtual machine
  • You can create your own
  • https://vagrantcloud.com/
  • http://www.vagrantbox.es/
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "precise64"
end

Vagrantfile

  • Ruby DSL for modifying and provisioning a box
  • Controls networking, memory, syched folders etc

Vagrant CLI

box manages boxes: installation, removal, etc. destroy stops and deletes all traces of the vagrant machine halt stops the vagrant machine init initializes a new Vagrant environment by creating a Vagrantfile plugin manages plugins: install, uninstall, update, etc. provision provisions the vagrant machine reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine ssh connects to machine via SSH suspend suspends the machine up starts and provisions the vagrant environment

Providers

  • VirtualBox
  • VmWare
  • Hyper-V
  • Amazon
  • Open stack
  • Docker

Configuring providers

config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    vb.customize ["modifyvm", :id, "--memory", mem_size ? mem_size : 6608]
    vb.customize ["modifyvm", :id, "--cpus",  num_cpus ? num_cpus : 2]
end

Syncing Folders

config.vm.synced_folder File.expand_path("../"), "/presentation"

Netorking

Support for forwarded ports, public and private networks etc

config.vm.network "forwarded_port", guest: 80, host: 8080

Multi Machine to mimic the topology of large systems

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: "echo Hello"

  config.vm.define "web" do |web|
    web.vm.box = "apache"
  end

  config.vm.define "db" do |db|
    db.vm.box = "mysql"
  end
end

Provisioning

  • Basic Usage
  • File
  • Shell
  • Ansible
  • Chef Solo
  • Chef Client
  • Docker
  • Puppet Apply
  • Puppet Agent
  • Salt
Vagrant.configure("2") do |config|
  config.vm.provision "shell",
    inline: "echo Hello, World"
end
config.vm.provision :chef_solo do |chef|
    chef.json = {
      :java => {
        :install_flavor => "oracle",
        :jdk_version => "7",
        :oracle => {
          "accept_oracle_download_terms" => true
        }
      }
    }

    chef.run_list = [
        "recipe[apt]",
        "recipe[git]",
        "recipe[java]",
        "recipe[mongodb::10gen_repo]",
        "recipe[mongodb]",
        "recipe[vertx]"
    ]
  end

Plugins

  • https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins
  • vagrant-triggers
  • vagrant-digitalocean
  • vagrant-guestip

Containers vs VMs

vagrant up --provider=docker

Provide scripts using vagrant ssh -c

Dev, QA, and your laptop can be clones of production

Rails Dev Box

Vagrant Manager