Download - Vagrant introduction for Developers
![Page 1: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/1.jpg)
Vagrant for Developers
![Page 2: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/2.jpg)
Presenter
- Technology Architect at Accenture
- 10+ years Enterprise Java Developmentg
- Areas of work:- Open Source activist- DevOps evangelist- Technical and OO Trainer- Cloud and PaaS development
http://www.linkedin.com/in/antonskranga
![Page 3: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/3.jpg)
Motivation
Basic Vagrant Usage
Provisioning with Cookbooks
Base Images Creation
Agenda
![Page 4: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/4.jpg)
Motivation
Basic Vagrant Usage
Provisioning with Cookbooks
Base Images Creation
Agenda
![Page 5: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/5.jpg)
Every
thing
installe
d
locally
We usingInfrastructure
as Code
Everybody
using
one big VM
How do you manage your Dev Env?
![Page 6: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/6.jpg)
Low or no automation at all
Long error-prone install guides
Painful maintenance or recovery
Painful rollback
No team collaboration
Host everything natviely
![Page 7: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/7.jpg)
Master Image contains:
- All software installed
- All configuration
Hosted typically in project File Server
Often maintained by one Person
No team collaboration
Master Image
![Page 8: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/8.jpg)
Master Image: Problems
Hard to distribute in big teams
Maintenance process is manual
Hard to maintain in parallel
Cannot use Version Control System
![Page 9: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/9.jpg)
Just Enough Operating System
![Page 10: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/10.jpg)
- Written declaratively (just enough ruby DSL)
- Repeatable
- OS agnostic
- Source control
- Help from Community
- Testable
JEOS
+censored
Naked OS Configuration
![Page 11: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/11.jpg)
V for Vagrant
www.vagrantup.com Off Sitewww.vagrantbox.es VM Imageshttps://github.com/opscode/bento VM Images from Chef
Useful Links:
![Page 12: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/12.jpg)
Vagrant
- Vagrant will mange VM for you
- Can create whole stack of VMs
- Describe VM resources in Configuration
- Can put configuration in Source Control
- Easy to distribute and update
![Page 13: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/13.jpg)
Motivation
Basic Vagrant Usage
Provisioning with Cookbooks
Base Images Creation
Agenda
![Page 14: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/14.jpg)
Quick start
shell
$ vagrant up
VagrantfileVagrant.configure "2" do |config|
config.vm.box = "vagrant-1"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
end
![Page 15: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/15.jpg)
Quick start v2
shell$ vagrant box add NAME http://files.vagrantup.com/precise64.box $ vagrant init
# modify Vagrantfile until you happy$ vagrant up
![Page 16: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/16.jpg)
Most useful commands
shell
$ vagrant ssh # Connect to VM
$ vagrant reload # Connect to VM
$ vagrant halt # Stop VM
$ vagrant destroy # delete VM
$ vagrant package # Create snapshot (.box file)
![Page 17: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/17.jpg)
Modifying scripts
VagrantfileVagrant.configure "2" do |config|
config.vm.box = "vagrant-1"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
end
![Page 18: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/18.jpg)
Modifying scripts
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = "vagrant-1"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.hostname = “vmhost"
end
![Page 19: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/19.jpg)
Modifying scripts
VagrantfileVagrant.configure "2" do |config|
config.vm.box = "vagrant-1"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.hostname = “vmhost"
config.vm.network :forwarded_port, guest: 80, host: 1080
end
![Page 20: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/20.jpg)
Modifying scripts
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = "vagrant-1"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.hostname = “vmhost"
config.vm.network :forwarded_port, guest: 80, host: 1080 config.vm.synced_folder “webapp/", "/var/www"end
![Page 21: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/21.jpg)
Modifying scripts
VagrantfileVagrant.configure "2" do |config|
config.vm.box = "vagrant-1"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.hostname = “vmhost"
config.vm.network :forwarded_port, guest: 80, host: 1080 config.vm.synced_folder “webapp/", "/var/www“
config.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--memory", 1024] endend
![Page 22: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/22.jpg)
Demo
![Page 23: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/23.jpg)
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.define :ubuntu1204 do |ubuntu1204| ubuntu1204.vm.box = "example4-ubuntu-12.10" ubuntu1204.vm.box_url = "http://files.vagrantup..." ubuntu1204.vm.hostname = "example4-ubuntu-1210" ubuntu1204.vm.network :forwarded_port, guest: 80, host: 1080 ubuntu1204.vm.network :private_network, ip: "34.33.33.10" end
config.vm.define :ubuntu1310 do |ubuntu1310| ubuntu1310.vm.box = "example4-ubuntu-13.10" ubuntu1310.vm.box_url = "http://files.vagrantup..." ubuntu1310.vm.hostname = "example4-ubuntu-1310" ubuntu1204.vm.network :forwarded_port, guest: 80, host: 2080 ubuntu1204.vm.network :private_network, ip: "34.33.33.11" end config.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--memory", 1024] endend
![Page 24: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/24.jpg)
Motivation
Basic Vagrant Usage
Provisioning with Cookbooks
Base Images Creation
Agenda
![Page 25: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/25.jpg)
- You declare what software you want
- Chef will provision it for you
- Over 1300 cookbooks
Chef
![Page 26: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/26.jpg)
Before you start
shell# install Chef plugin$ vagrant plugin install vagrant-omnibus
# install Berkshelf plugin$ vagrant plugin install vagrant-berkshelf
# Kind of apt-cache for Vagrant$ vagrant plugin install vagrant-cachier
![Page 27: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/27.jpg)
Update configuration
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = "vagrant-5" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.hostname = “localhost" config.vm.network :forwarded_port, guest: 80, host: 1080 config.vm.synced_folder “webapp/", "/var/www“
config.omnibus.chef_version = :latest config.berkshelf.enabled = true config.cache.auto_detect = trueend
![Page 28: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/28.jpg)
Update configuration
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = "vagrant-5" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.hostname = “localhost" config.vm.network :forwarded_port, guest: 80, host: 1080 config.vm.synced_folder “webapp/", "/var/www“
config.omnibus.chef_version = :latest config.berkshelf.enabled = true config.cache.auto_detect = true
config.vm.provision :chef_solo do |chef| chef.add_recipe “apache2“ endend
![Page 29: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/29.jpg)
Create berkshelf configuration
Berksfilesite :opscode
metadata
cookbook "apache2"
![Page 30: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/30.jpg)
Provisioning commands
shell# to provision for first time just enough$ vagrant up
# to restart VM$ vagrant reload --provision
# to provision without restart$ vagrant provision
![Page 31: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/31.jpg)
Demo
![Page 32: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/32.jpg)
Create berkshelf configuration
Berksfile
site :opscode
metadata
cookbook 'apt'cookbook 'git'cookbook 'tomcat', git: "https://github.com/opscode-cookbooks/tomcat.git"cookbook 'maven'cookbook 'mongodb'# cookbook 'mycookbook', :path => "cookbooks/mycookbook"
![Page 33: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/33.jpg)
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = "vagrant-5" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.hostname = “localhost" config.vm.network :forwarded_port, guest: 8080, host: 1080
config.omnibus.chef_version = :latest config.berkshelf.enabled = true config.cache.auto_detect = true
config.vm.provision :chef_solo do |chef| chef.add_recipe "mongodb::10gen_repo" chef.add_recipe "apt" chef.add_recipe "git" chef.add_recipe "maven" chef.add_recipe "mongodb" chef.add_recipe "tomcat" endend
![Page 34: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/34.jpg)
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = "vagrant-5" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.hostname = “localhost" config.vm.network :forwarded_port, guest: 8080, host: 1080
...
config.vm.provision :chef_solo do |chef| chef.add_recipe "mongodb::10gen_repo" chef.add_recipe "apt" chef.add_recipe "git" chef.add_recipe "maven" chef.add_recipe "mongodb" chef.add_recipe "tomcat" chef.json = { "java" => { "jdk_version" => "7", "install_flavor" => "openjdk" } } endend
![Page 35: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/35.jpg)
Vagrantfile
Vagrant.configure "2" do |config|
config.vm.box = "vagrant-5" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.hostname = “localhost" config.vm.network :forwarded_port, guest: 8080, host: 1080
...
config.vm.provision :chef_solo do |chef| chef.add_recipe "mongodb::10gen_repo" chef.add_recipe "apt" chef.add_recipe "git" chef.add_recipe "maven" chef.add_recipe "mongodb" chef.add_recipe "tomcat" chef.json = { "java" => { "jdk_version" => "7", "install_flavor" => "oracle", "accept_oracle_download_terms" => true } } endend
![Page 36: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/36.jpg)
Motivation
Basic Vagrant Usage
Provisioning with Cookbooks
Base Images Creation
Agenda
![Page 37: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/37.jpg)
Motivation
Custom project specifics
OS-level patching
Produce Stemcells(preinstalled images)
True Infra-as-code
![Page 38: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/38.jpg)
Tools we need“Packer is a tool for creating identical machine images for multiple platforms…”
- Off Site: packer.io- Written in Go- Must be installed to ~/pakcer
“Bento is set of Packer templates for building Vagrant baseboxes”
- Off Site: opscode.github.io/bento/- Maintained by Chef
![Page 39: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/39.jpg)
Shell$ git clone https://github.com/opscode/bento.git$ cd bento/packerbento/packer $ packer build ubuntu-13.10-amd64.json
Quick start with Packer
![Page 40: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/40.jpg)
Shell$ git clone https://github.com/opscode/bento.git$ cd bento/packerbento/packer $ packer build ubuntu-13.10-amd64.json
Quick start with Packer
![Page 41: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/41.jpg)
Shellbento/packer $ packer build \ -only=virtualbox-iso \ ubuntu-13.10-amd64.json
Little bit more tuning
![Page 42: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/42.jpg)
Shellbento/packer $ packer build \ -only=virtualbox \ -var-file=variables.json ubuntu-13.10-amd64.json
Little bit more tuning
variables.json{ "chef_version": "latest", "mirror": "../builds/iso/"}
![Page 43: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/43.jpg)
Demo
![Page 44: Vagrant introduction for Developers](https://reader033.vdocuments.site/reader033/viewer/2022061223/54c688f74a7959a2128b466a/html5/thumbnails/44.jpg)
Thank You!