vagrant - version control your dev environment
DESCRIPTION
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-lampdemoTRANSCRIPT
![Page 1: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/1.jpg)
VagrantVersion control your dev environment
Bob Cribbs
![Page 2: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/2.jpg)
Bob Cribbs
Software developer.Focused mainly on Python, junior on Ruby and getting started with mobile.
bocribbz.com
bocribbz bocribbz
bocribbzbocribbz
bocribbz
![Page 3: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/3.jpg)
www.vagrantup.com
Development environments
made easy.
Brasov Tech Meet | September 2013
![Page 4: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/4.jpg)
You’re hired. Get the project up and running on your new machine.newguy$ git clone git://path-to-code-repo/super_project.gitCloning into super_projectnewguy$ cd super_project
newguy$ ...
newguy$ ./start.shServer listening on 127.0.0.1
![Page 5: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/5.jpg)
newguy$ ./setup.shInstalling software.Installing dependencies.Configuring.Success!
We have a setup script!
![Page 6: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/6.jpg)
We have a setup script!
● multiple ecosystems Win/Linux/MacOS
● multiple package managers yum, apt, home-
brew, macports
● its likely some configuration will be done
differently
● its likely it will diverge from the production
environment
![Page 7: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/7.jpg)
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.
![Page 8: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/8.jpg)
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
![Page 9: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/9.jpg)
I’m sure you can do it!newguy$ start.shFailed to connect to MySql at localhost:3333newguy$ install mysql
newguy$ start.shFailed to connect to Redis at localhost:3334newguy$ install redis
newguy$ start.shMissing ImageMagick extensions.newguy$ install imagemagick
newguy$ start.shServer listening on 127.0.0.1
![Page 10: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/10.jpg)
I’m sure you can do it!
Internal Server Error!
![Page 11: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/11.jpg)
Problems
Not repeatable.Not verifiably correct.Not isolated.Difficult to understand.
![Page 12: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/12.jpg)
Problems
Not repeatable.Not verifiably correct.Not isolated.Difficult to understand.
SLOW, SLOW, SLOW!
![Page 13: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/13.jpg)
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
Vagrant
![Page 14: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/14.jpg)
Problems solved
Repeatableyou can do the exact same thing when needed
Verifiably correctyou should have automation to check this
Isolatedits in a virtual machine (Vbox, VMWare, etc.)
UnderstandableYou can read it to understand
Fast(er)It still takes some time, but it is much faster
![Page 15: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/15.jpg)
Boxestemplates for creating a machine, preinstalled OS
Some Terms
![Page 16: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/16.jpg)
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
![Page 17: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/17.jpg)
Some Terms
Boxestemplates for creating a machine, preinstalled OS
Vagrantfileconfiguration read by vagrant to create your machine
![Page 18: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/18.jpg)
Vagrantfile samplesVagrant.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
![Page 19: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/19.jpg)
Some Terms
Boxestemplates for creating a machine, preinstalled OS
Vagrantfileconfiguration read by vagrant to create your machine
"vagrant" commandmanages life cycle of the environment
![Page 20: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/20.jpg)
"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
![Page 21: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/21.jpg)
newguy$ git clone git://path-to-code-repo/super_project.gitCloning into super_projectnewguy$ cd super_project
newguy$ vagrant up
You’re hired. Get the project up and running on your new machine.
![Page 22: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/22.jpg)
Overview
1. Project specific configuration file
2. Import base box
3. Boot up virtual machinea. Synced folders
b. Networking
4. Configure / provision software
![Page 23: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/23.jpg)
Synced Folders
Automatically sync files from host to guest so you can use your prefered editor on the host.
VirtualBox shared foldersVMWare shared folderrsync (for AWS)etc...
![Page 24: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/24.jpg)
Synced Folders configVagrant.configure("2") do |config|
# ...
config.vm.shared_folder "path/on/host/", "/path/on/guest/"
end
![Page 25: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/25.jpg)
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 forwardingHost-Only: private networkBridge: act like a new device on the router/network
![Page 26: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/26.jpg)
Networking configVagrant.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
![Page 27: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/27.jpg)
Provisioning
You can use shell scripts, Puppet or Chef to install and configure software.
BerkshelfCreate and manage cookbooks that install and configure software dependencies.ChefAutomation platform and nodes manager.Transforms infrastructure into code.
![Page 28: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/28.jpg)
Provisioning configsVagrant.configure("2") do |config|
# ...
config.vm.provision "shell", script "setup.sh"
end
![Page 29: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/29.jpg)
Berkshelf
Manage cookbook and it’s dependencies.http://community.opscode.com/
Create new cookbook and boilerplate configuration:berks cookbook cookbook-projectname
![Page 30: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/30.jpg)
Examplehttps://github.com/bocribbz/cookbook-lampdemo
![Page 31: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/31.jpg)
LAMP demo
Show how Vagrant and Berkshelf work together.
Simple cookbook that installs Ubuntu, Apache, MySQL, PHP and shows phpinfo().
![Page 32: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/32.jpg)
LAMP demo
berks cookbook cookbook-lampdemo
![Page 33: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/33.jpg)
LAMP demo - Vagrantfile
![Page 34: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/34.jpg)
LAMP demo - metadata.rb
![Page 35: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/35.jpg)
LAMP demo - Apache attributes
Setting attributes/apache.rb paths and other variables used in the recipe.
![Page 36: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/36.jpg)
LAMP demo - Apache recipe
![Page 37: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/37.jpg)
LAMP demo - PHP recipe
![Page 38: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/38.jpg)
LAMP demo - MySQL attrs & recipe
![Page 39: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/39.jpg)
LAMP demo - vagrant up
![Page 40: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/40.jpg)
LAMP demo
![Page 41: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/41.jpg)
Questions
![Page 42: Vagrant - Version control your dev environment](https://reader033.vdocument.in/reader033/viewer/2022060107/554a32d5b4c90542548b56f0/html5/thumbnails/42.jpg)
Thank you!