Vagrant to the rescue

Db6218c1b56d64e775eb79ea4f2889dd?s=47 Sebastian
February 05, 2015

Vagrant to the rescue

Many developers know the pain of setting up a development machine and share the setup with the team - Putting the same folders in the same place, keeping configurations in sync and managing external dependencies. Vagrant solves this problem by creating a development environment inside a virtual machine and making it easy to share with other developers. Within this talk, I'll take the audience on a trip from a time where everybody would install stuff on localhost until the software starts working to a land where the environment one develops in mirrors the production environment as closely as possible without changing the laptop/pc of the developer. I'll talk about devops and configuration management briefly and show how one can get started with vagrant. After this talk, the audience knows what problems vagrant solves and how to get started.

Db6218c1b56d64e775eb79ea4f2889dd?s=128

Sebastian

February 05, 2015
Tweet

Transcript

  1. Vagrant to the rescue PHP London February 2015 @Sgoettschkes http://nos.twnsnd.co/image/95830917309

  2. None
  3. “It works on my machine”

  4. “It’s all in SETUP.md”

  5. Enter vagrant

  6. Building blocks Configuration + Provider + Base Boxes + Provisioner

    + Plugins = Vagrant http://pixabay.com/static/uploads/photo/2010/12/10/08/salad-1105_640.jpg
  7. Configuration Vagrant.configure(2) do |config| config.vm.box = "Sgoettschkes/debian7-ansible" config.vm.network "private_network", ip:

    "127.0.0.101" config.vm.synced_folder "../", "/srv/workspace" config.vm.provision "chef_solo" do |chef| chef.add_recipe "main" end end
  8. Providers

  9. Base Boxes Base Boxes • Image from VM • Provider-specific

    • Distribution through ◦ HTTP ◦ “Atlas” http://upload.wikimedia.org/wikipedia/commons/9/91/Shipping_containers_at_Clyde.jpg
  10. Provisioners

  11. Plugins # AWS provider $ vagrant plugin install vagrant-aws #

    Boxen provisioner $ vagrant plugin install ventriloquist # Manage host files $ vagrant plugin install vagrant-hostmanager # Make screenshots of your VM $ vagrant plugin install vagrant-camera # … many more!
  12. Synced folders http://upload.wikimedia.org/wikipedia/commons/5/5d/BalticServers_data_center.jpg # Vagrantfile config.vm.synced_folder "~/local/path/to/project", # on host

    "/opt/project" # on guest
  13. SSH http://pixabay.com/static/uploads/photo/2013/04/08/22/48/tunnel-101976_640.jpg $ vagrant ssh # or $ ssh -p

    2222 vagrant@localhost # with password “vagrant”
  14. http://freehddesktopwallpaper.info/wp-content/uploads/2013/06/Blue-Flowers-hd-Wallpapers.jpg Basic workflow

  15. Basic workflow $ vagrant init Sgoettschkes/debian7-ansible $ vagrant up #

    box is booting $ vagrant ssh # It’s actually a normal, headless VM! $ exit
  16. Basic workflow $ vim Vagrantfile # change config # add

    provisioners and so on $ git init $ git commit -Am ‘I am using Vagrant now!’ # Keep the Vagrantfile and files needed for provisioning # in git (or any other scm) to share with others
  17. Basic workflow $ git clone git@github.com:awesomecompany/awesomeVm.git $ cd awesomeVm &&

    vagrant up # VM is setup the same as on your co-workers machine # You can now work on your project
  18. Basic workflow # Co-worker updated Vagrantfile/provisioning files $ git pull

    --rebase $ vagrant provision # VM is up to date again
  19. Basic workflow # You wanna change some Vagrant related stuff

    $ vim Vagrantfile # Change it! $ vim playbook.yml # Change something here as well, maybe? $ vagrant provision # Your box is up to date again $ git commit -am ‘Incredible changes’ && git push
  20. Use cases

  21. Use cases Development environment

  22. Use cases Development environment Testing environment

  23. Use cases Development environment Testing environment Local test box for

    PMs & Designer
  24. Use cases Development environment Testing environment Local test box for

    PMs & Designer Playing around
  25. Use cases Development environment Testing environment Local test box for

    PMs & Designer Playing around with clusters
  26. Use cases Development environment Testing environment Local test box for

    PMs & Designer Playing around with clusters Open Source projects
  27. https://www.dropbox.com/s/mfmusz1qjotilbs/2H.jpg Best practices

  28. Base Boxes The fewer, the better

  29. Provisioning Idempotent

  30. Provisioning One step

  31. Provisioning # Bad: $ vagrant up $ install software x

    $ run script y $ create z
  32. Provisioning # Good: $ vagrant up

  33. Vms per Developer The fewer, the better (again)

  34. … Performance?

  35. http://nos.twnsnd.co/image/108652898544 What else is there?

  36. Multi-VM setup Vagrant.configure(2) do |config| config.vm.box = "Sgoettschkes/debian7" config.vm.define "web1"

    do |web1| web1.vm.network "private_network", ip: "192.168.1.150" end config.vm.define "db1" do |db1| db.vm.network "private_network", ip: "192.168.1.151" end end
  37. Multi-VM setup Vagrant.configure(2) do |config| config.vm.box = "Sgoettschkes/debian7" config.vm.define "web1"

    do |web1| web1.vm.network "private_network", ip: "192.168.1.150" end config.vm.define "db1" do |db1| db.vm.network "private_network", ip: "192.168.1.151" end end
  38. Vagrant share $ vagrant share # Your VM is now

    accessible through a public url # You can go back doing awesome work!
  39. Vagrant push config.push.define "ftp" do |push| push.dir = "/srv/workspace" push.host

    = "ftp.awesomeCompany.com" end
  40. Vagrant push config.push.define "local-exec" do |push| push.script = "deploy.sh" end

  41. Vagrant “Development environments made easy” http://fc02.deviantart.net/fs50/i/2009/315/4/c/Tweaked_toy_airplane_by_afd.jpg

  42. https://www.dropbox.com/s/6z5aiwa8l09g2pa/86H.jpg