Vagrant are you still develop in a non-virtual environment-
Vagrant: are you stilldevelop in a non-virtualenvironment?Then we are coming to you!Anatoly BubenkovPaylogichttp://github.com/bubenkoffMonthly PyGrunn June 11 2013
Ok, Im starting a project, what do Ineed? (worst case)● Centos 4 (but I like my Ubuntu 13.04)!● MySQL (what??)● MongoDB (oh...)● SOLR● RabbitMQ● node.js● python 2.4 :)● lots of system packages installed fromexternal sourcesWell, I dont want to install that on my machine,and actually cant!
Back to the past: can you please fixthat bug in a 2-years old project?● I dont even remember what was there...● Ok Ive found the code, but how do I createthe test data?● Spent hours to get it all working back...
As a Developer, I need theenvironment which is:● fully functional (eg. no limitations justbecause of its hard to set up locally)● reproducable (fast to reproduce same stuffon another machine in minutes)● as close to production environment aspossible● versioned (easy to make a savepoint, toreturn to if any need and at any time)● independent (no direct dependency on mymachine)
Possible solutions:● 1 mb long INSTALL.txt :) - the hard way● Deployment automation tools (Puppet andetc) - need a clean machine● docker.io - ubuntu specific (for now)● or ...
How it works?Vagrant core(command line)VirtualboxVmWareProvidersAmazonAWSProvisionersShellPuppet (ruby script)Chef (ruby script)Ansible (YAML config)Base boxInstanceBase boxInstanceBase boxInstance
InstallationExists for:● Windows● Linux● Mac OS
Easy example:$ vagrant init precise32 http://files.vagrantup.com/precise64.box$ vagrant upAfter running the above two commands, youllhave a fully running virtual machine inVirtualBox running Ubuntu 12.04 LTS 64-bit.
ConfigurationVagrantfile - configuration entry point (a ruby script)Vagrant loads a series of Vagrantfiles, merging the settingsas it goes.Ordering:/home/mitchellh/projects/foo/Vagrantfile/home/mitchellh/projects/Vagrantfile/home/mitchellh/Vagrantfile/home/Vagrantfile/VagrantfileOn each level, Vagrant will merge settings in.
Boxes● Vagrant boxes are skeletons to rely on when you buildyour own instance.● Provider-specific● Contain metadata and helper files to deploy● Adding a box:$ vagrant box add name url● List:$ vagrant box listprecise64 (virtualbox)precise64 (vmware_fusion)● Remove:$ vagrant box remove precise64 virtualbox
ProvisionersProvisioning is a process of making your basebox the box you need.Vagrant.configure("2") do |config|# ... other configurationconfig.vm.provision :shell, :inline => "mkdir /etc/app"end● shell● chef● puppet● ansible
Networking● High level configuration is provider-independend● Low level configuration is provider specific● Multiple networks are supported at once
Synced folders● Transparently configure shared folders viavirtualization providers● By default, Vagrant will share your projectdirectory (the directory with theVagrantfile) to/vagrant.● But for the code, I prefer to share it FROMvirtual machine to host machine (NFS)
Multi-machine setup!● You can configure several machines insingle Vagrantfile:Vagrant.configure("2") do |config|config.vm.provision :shell, :inline => "echo Hello"config.vm.define :web do |web|web.vm.box = "apache"endconfig.vm.define :db do |db|db.vm.box = "mysql"endend● Start/stop them all or separately:vagrant upvagrant up webvagrant up db
PluginsUseful for me:● vagrant-vbox-snapshot - snapshotmanagement for vbox provider● vagrant-vbguest - autoinstallation of vboxguest additionsInstallation is as simple as:$ vagrant plugin install <plugin name>
But, but any consequences?● System memory - you need it enough● Disk - you need a complete OS on virtualmachine, be prepared to give at least 10 Gbper instance.● Setting up network fs (NFS) - but thats onlyfor those who dont know vim :)● Speed - of course theres some slowdowndue virtualization.