Vagrant
Version control your dev environment

Bob Cribbs
Bob Cribbs
Software developer.
Focused mainly on Python, junior on Ruby and
getting started with mobile.
bocribbz

bocribb...
Development
environments
made easy.

www.vagrantup.com

Brasov Tech Meet | September 2013
You’re hired. Get the project up and running
on your new machine.
newguy$ git clone git://path-to-code-repo/super_project....
We have a setup script!
newguy$ ./setup.sh
Installing software.
Installing dependencies.
Configuring.
Success!
We have a setup script!
● multiple ecosystems Win/Linux/MacOS
● multiple package managers yum, apt, homebrew, macports
● i...
We have a README!
It gives precise instructions about what should
be installed and how it should be configured.

For a mat...
We have a README!
● multiple ecosystems Win/Linux/MacOS
● very high chances something will be
misconfigured
● unlikely to ...
I’m sure you can do it!
newguy$ start.sh
Failed to connect to MySql at localhost:3333
newguy$ install mysql
newguy$ start....
I’m sure you can do it!
Internal Server Error!
Problems
Not repeatable.
Not verifiably correct.
Not isolated.
Difficult to understand.
Problems
Not repeatable.
Not verifiably correct.
Not isolated.
Difficult to understand.

SLOW, SLOW, SLOW!
Vagrant
Its a tool for creating, managing and distributing
portable development environments.
Zero to VM in seconds
$ vagr...
Problems solved
Repeatable
you can do the exact same thing when needed

Verifiably correct
you should have automation to c...
Some Terms
Boxes
templates for creating a machine, preinstalled OS
Boxes
Snapshots / base operating system images.
Initial state of the VM.
Operating system (Ubuntu 12.04, CentOS 5.9,
etc.)...
Some Terms
Boxes
templates for creating a machine, preinstalled OS

Vagrantfile
configuration read by vagrant to create yo...
Vagrantfile samples
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
end

Vagrant.configure("2") do |config|...
Some Terms
Boxes
templates for creating a machine, preinstalled OS

Vagrantfile
configuration read by vagrant to create yo...
"vagrant" command
vagrant init

Create a Vagrantfile in the current directory
vagrant up

Boot the VM
vagrant halt

Shutdo...
You’re hired. Get the project up and running
on your new machine.
newguy$ git clone git://path-to-code-repo/super_project....
Overview
1. Project specific configuration file
2. Import base box
3. Boot up virtual machine
a. Synced folders
b. Network...
Synced Folders
Automatically sync files from host to guest so
you can use your prefered editor on the host.
VirtualBox sha...
Synced Folders config
Vagrant.configure("2") do |config|
# ...
config.vm.shared_folder "path/on/host/",
"/path/on/guest/"
...
Networking
Configure how you will communicate with the VM or how
multiple VMs communicate with each other.
You can still u...
Networking config
Vagrant.configure("2") do |config|
# ...
config.vm.network :forwarded_port, guest: 80, host: 8080
config...
Provisioning
You can use shell scripts, Puppet or Chef to
install and configure software.
Berkshelf
Create and manage cook...
Provisioning configs
Vagrant.configure("2") do |config|
# ...
config.vm.provision "shell", script "setup.sh"
end
Berkshelf
Manage cookbook and it’s dependencies.
http://community.opscode.com/
Create new cookbook and boilerplate configu...
Example
https://github.com/bocribbz/cookbook-lampdemo
LAMP demo
Show how Vagrant and Berkshelf work together.
Simple cookbook that installs Ubuntu, Apache,
MySQL, PHP and shows...
LAMP demo
berks cookbook cookbook-lampdemo
LAMP demo - Vagrantfile
LAMP demo - metadata.rb
LAMP demo - Apache attributes
Setting attributes/apache.rb paths and other
variables used in the recipe.
LAMP demo - Apache recipe
LAMP demo - PHP recipe
LAMP demo - MySQL attrs & recipe
LAMP demo - vagrant up
LAMP demo
Questions
Thank you!
Upcoming SlideShare
Loading in …5
×

Vagrant - Version control your dev environment

2,528 views
2,215 views

Published on

Vagrant facilitates the creation and configuration of lightweight, reproducible, and portable development environments.
It is currently in use at companies like Disqus, BBC, Mozilla, Nokia, and O'Reilly Media. More information about Vagrant is available at: http://www.vagrantup.com/

Links:
Boxes: https://github.com/opscode/bento
Cookbooks: http://community.opscode.com/
LAMP demo: https://github.com/bocribbz/cookbook-lampdemo

Published in: Technology
2 Comments
6 Likes
Statistics
Notes
  • @sepehrnow thanks for the recommendation. I'll explore Salt on some personal projects.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Cool, Vagrant+Chef can save so much time. But I'm hearing a lot of good things about Vagrant+Salt too. Salt is python based so it seems like a more natural option for a python guy.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,528
On SlideShare
0
From Embeds
0
Number of Embeds
598
Actions
Shares
0
Downloads
19
Comments
2
Likes
6
Embeds 0
No embeds

No notes for slide

Vagrant - Version control your dev environment

  1. 1. Vagrant Version control your dev environment Bob Cribbs
  2. 2. Bob Cribbs Software developer. Focused mainly on Python, junior on Ruby and getting started with mobile. bocribbz bocribbz bocribbz bocribbz bocribbz bocribbz.com
  3. 3. Development environments made easy. www.vagrantup.com Brasov Tech Meet | September 2013
  4. 4. You’re hired. Get the project up and running on your new machine. newguy$ git clone git://path-to-code-repo/super_project.git Cloning into super_project newguy$ cd super_project newguy$ ... newguy$ ./start.sh Server listening on 127.0.0.1
  5. 5. We have a setup script! newguy$ ./setup.sh Installing software. Installing dependencies. Configuring. Success!
  6. 6. We have a setup script! ● multiple ecosystems Win/Linux/MacOS ● multiple package managers yum, apt, homebrew, macports ● its likely some configuration will be done differently ● its likely it will diverge from the production environment
  7. 7. We have a README! It gives precise instructions about what should be installed and how it should be configured. For a mature project, the README file ends up being a few screens long.
  8. 8. We have a README! ● multiple ecosystems Win/Linux/MacOS ● very high chances something will be misconfigured ● unlikely to be maintained, (most) developers don’t write English ● time consuming
  9. 9. I’m sure you can do it! newguy$ start.sh Failed to connect to MySql at localhost:3333 newguy$ install mysql newguy$ start.sh Failed to connect to Redis at localhost:3334 newguy$ install redis newguy$ start.sh Missing ImageMagick extensions. newguy$ install imagemagick newguy$ start.sh Server listening on 127.0.0.1
  10. 10. I’m sure you can do it! Internal Server Error!
  11. 11. Problems Not repeatable. Not verifiably correct. Not isolated. Difficult to understand.
  12. 12. Problems Not repeatable. Not verifiably correct. Not isolated. Difficult to understand. SLOW, SLOW, SLOW!
  13. 13. Vagrant Its a tool for creating, managing and distributing portable development environments. Zero to VM in seconds $ vagrant init precise32 http://files.vagrantup.com/precise32.box ... $ vagrant up ... $ vagrant ssh vagrant@precisebox32:~$ echo hello hello
  14. 14. Problems solved Repeatable you can do the exact same thing when needed Verifiably correct you should have automation to check this Isolated its in a virtual machine (Vbox, VMWare, etc.) Understandable You can read it to understand Fast(er) It still takes some time, but it is much faster
  15. 15. Some Terms Boxes templates for creating a machine, preinstalled OS
  16. 16. Boxes Snapshots / base operating system images. Initial state of the VM. Operating system (Ubuntu 12.04, CentOS 5.9, etc.) Can be packaged and shared. eg. https://github.com/opscode/bento
  17. 17. Some Terms Boxes templates for creating a machine, preinstalled OS Vagrantfile configuration read by vagrant to create your machine
  18. 18. Vagrantfile samples Vagrant.configure("2") do |config| config.vm.box = "precise32" end Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.provision "shell" inline "apt-get update" config.vm.provision "shell" inline "apt-get install apache2" end
  19. 19. Some Terms Boxes templates for creating a machine, preinstalled OS Vagrantfile configuration read by vagrant to create your machine "vagrant" command manages life cycle of the environment
  20. 20. "vagrant" command vagrant init Create a Vagrantfile in the current directory vagrant up Boot the VM vagrant halt Shutdown the VM vagrant destroy Delete the virtual machine vagrant ssh SSH into the VM
  21. 21. You’re hired. Get the project up and running on your new machine. newguy$ git clone git://path-to-code-repo/super_project.git Cloning into super_project newguy$ cd super_project newguy$ vagrant up
  22. 22. Overview 1. Project specific configuration file 2. Import base box 3. Boot up virtual machine a. Synced folders b. Networking 4. Configure / provision software
  23. 23. Synced Folders Automatically sync files from host to guest so you can use your prefered editor on the host. VirtualBox shared folders VMWare shared folder rsync (for AWS) etc...
  24. 24. Synced Folders config Vagrant.configure("2") do |config| # ... config.vm.shared_folder "path/on/host/", "/path/on/guest/" end
  25. 25. Networking Configure how you will communicate with the VM or how multiple VMs communicate with each other. You can still use your prefered browser or tools to communicate with the guest servers. NAT: usually for port forwarding Host-Only: private network Bridge: act like a new device on the router/network
  26. 26. Networking config Vagrant.configure("2") do |config| # ... config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "192.168.3.10" config.vm.network :public_network end
  27. 27. Provisioning You can use shell scripts, Puppet or Chef to install and configure software. Berkshelf Create and manage cookbooks that install and configure software dependencies. Chef Automation platform and nodes manager. Transforms infrastructure into code.
  28. 28. Provisioning configs Vagrant.configure("2") do |config| # ... config.vm.provision "shell", script "setup.sh" end
  29. 29. Berkshelf Manage cookbook and it’s dependencies. http://community.opscode.com/ Create new cookbook and boilerplate configuration: berks cookbook cookbook-projectname
  30. 30. Example https://github.com/bocribbz/cookbook-lampdemo
  31. 31. LAMP demo Show how Vagrant and Berkshelf work together. Simple cookbook that installs Ubuntu, Apache, MySQL, PHP and shows phpinfo().
  32. 32. LAMP demo berks cookbook cookbook-lampdemo
  33. 33. LAMP demo - Vagrantfile
  34. 34. LAMP demo - metadata.rb
  35. 35. LAMP demo - Apache attributes Setting attributes/apache.rb paths and other variables used in the recipe.
  36. 36. LAMP demo - Apache recipe
  37. 37. LAMP demo - PHP recipe
  38. 38. LAMP demo - MySQL attrs & recipe
  39. 39. LAMP demo - vagrant up
  40. 40. LAMP demo
  41. 41. Questions
  42. 42. Thank you!

×