Virtualization with Vagrant (ua.pycon 2011)

3,058 views

Published on

Presentation on topic of using virtualized environment in development and testing, especially for web applications.

Prepared for Pycon Ukraine 2011

Published in: Technology
0 Comments
11 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,058
On SlideShare
0
From Embeds
0
Number of Embeds
794
Actions
Shares
0
Downloads
42
Comments
0
Likes
11
Embeds 0
No embeds

No notes for slide

Virtualization with Vagrant (ua.pycon 2011)

  1. 1. Virtual testing &development** batteries included
  2. 2. $ git clone git://server.com/project.git$ runIdeal world
  3. 3. $ git clone git://server.com/project.gitReal world
  4. 4. $ git clone git://server.com/project.git... read help$ mkdir, cp, vim config.conf, configure, make, makeinstall... ask guru$ /project/hidden/blackmagic --fix_that --fix_this --undocumented_parameter=MAGIC_CONST_42... %^ing @#$@#%@!!!!Real world
  5. 5. $ git clone git://server.com/project.git... read help$ mkdir, cp, vim config.conf, configure, make, makeinstall... ask guru$ /project/hidden/blackmagic --fix_that --fix_this --undocumented_parameter=MAGIC_CONST_42... %^ing @#$@#%@!!!!$ runReal world
  6. 6. Why?
  7. 7. Operating SystemUser SpaceMusicWebServerDBAppServerIMEditorBrowser
  8. 8. Problems• No isolation (oh, wrong binary onpath...?)• Not repeatable (that README ain’tgonna run itself!)• No guarantees (“..but it works on mycomputer!”)
  9. 9. Solution?
  10. 10. Operating SystemMusicWebServer DBAppServerIM EditorBrowserUser SpaceVirtualized OS
  11. 11. Benefits• Isolation (project and version specificfiles only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  12. 12. Business benefits• Reduce costs (less hardware, lower energyconsumption)• Backup and data protection• Application availability• Less time to respond to changing businessneeds• Less time spent on routine tasks• Better IT department perception
  13. 13. Time spend on routine tasksaccording to VMware small & medium business survey
  14. 14. Why haven’t we been doingthis for a long time?• Big companies have been• Amazon EC2• Microsoft• Google• Only recently possible on local machines• Cheat hardware• Cheap RAM• Desktop virtualization API
  15. 15. Ok, let’s go virtual.Now what?
  16. 16. Vagrant is a tool for building anddistributing virtualized developmentenvironments (vagrantup.com)
  17. 17. VirtualBox is cross-platform virtualization softwarethat works on all the major platforms(virtualbox.org)
  18. 18. High level overview• Describe environment with Vagrantfiles• Command line interface to manage VM lifecycle• Automate provisioning and configuration• Share folder with host OS via NFS• Provide SSH access to guest OS• Network multiple VMs• Package and distribute VMs
  19. 19. Vagrant boxes• Box = pre-packaged VM environment (~OSimage)• A number of ready to use boxes @ http://vagrantbox.es• Ubuntu 32 / 64• CentOS• Solaris• RH
  20. 20. Vagrantfile• Vagrantfile is to Vagrant as Makefile is toMake• Describes VM in code• One Vagrantfile per project (can containmultiple VMs)• Commit it to version control• Actually a Ruby code - easy to extent
  21. 21. VagrantfileVagrant::Config.run do |config|config.vm.box = “base_ubuntu"end
  22. 22. Command line$ vagrant helpvagrant initvagrant upvagrant haltvagrant reloadvagrant suspendvagrant resumevagrant destroyvagrant provisionvagrant package…
  23. 23. • Isolation (project and versionspecific files only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  24. 24. Chef is an open-source systemsintegration framework built specificallyfor automating the cloud (opscode.com/chef)
  25. 25. Puppet is a system for automatingsystem administration tasks, workson most UNIX-like operatingsystems (puppetlabs.com)
  26. 26. How Chef/Puppet works• You create recipes• Recipes describe desired system state• Then you manage your server park• Safely• Repeatedly• In automated way
  27. 27. Provisioning in Vagrant• Use Chef, Puppet, bash scripts, etc. tomanage VM configuration• Repeatable!• Use same tools for production - Chef,Puppet
  28. 28. Vagrant + ChefVagrant::Config.run do |config|config.vm.box = “base_ubuntu_box"config.vm.provision :chef_solo do |chef|chef.recipe_url = "http://server/cookbooks.tar.gz"chef.add_recipe(“aptitude")chef.add_recipe(“apache2")chef.add_recipe(“mysql-server")chef.add_recipe(“python27")chef.add_recipe(“pip")endend
  29. 29. Networking• Assign IP to VM in Vagrantfile• Forward ports• Access VM from your browser
  30. 30. NetworkingVagrant::Config.run do |config|config.vm.box = "lucid32"config.vm.network("10.20.30.49")config.vm.forward_port("web", 80, 4567)end
  31. 31. • Isolation (project and versionspecific files only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  32. 32. Packaging• When environment is stable• Package and distribute prepared VMs• Minimize setup time
  33. 33. • Isolation (project and versionspecific files only)• Repeatable (snapshots, copies,automation)• Guarantees (same OS different day)
  34. 34. Beyond that• Multi-VM Vagrantfile• DB• AppServer• WebServer• Use vagrant as library• Call API functions to do the tasks fromRuby code• Run custom SSH commands
  35. 35. Demohttp://youtu.be/O3-MNsowgHc
  36. 36. Demogithub.com/dreamiurg/timetest•Django application•Apache2 + MySQL on single VM•Additional Python packages like used (South, annoying)•DB migrations handled by South•Deployment process• Vagrant is used to create VM, install required packages andconfigure services• Fabric (fabfile.org) is used to populate DB, set up apache2 confand install Python modules
  37. 37. Prerequisites$ <install python>$ <install ruby>$ <install virtualbox>$ gem install vagrant$ git clone http://server/project.git$ cd project
  38. 38. Demo: create VM, deploy project00:00:00 $ vagrant box add base http://server/base.box... base box for VM is copied to your computer00:02:00 $ vagrant up... vagrant creates VM from base box, installs and configuresrequired packages – apt, apache2, mysql, python, git, …00:05:00 $ fab deploy... DB is populated with initial data, apache config updated, apacherestarted00:07:00 $ curl http://localhost:8080/... site is up and running.
  39. 39. Real world
  40. 40. Our experience• 10+ projects during last 18 months• From small (single webserver, no DB) tomedium (several webservers + load balancer,master/slave DB replication)• New developer start time reduced from 2-3days to 1 hr on average• Number of deployment/environment defectsreduced by 75%
  41. 41. Links• http://vagrantup.com• http://www.vagrantbox.es• http://fabfile.org• http://opscode.com• http://puppetlabs.com• http://github.com/dreamiurg/timetest• http://www.vmware.com/files/pdf/VMware-SMB-Survey.pdf
  42. 42. Dmitry Guyvoronskyhttp://about.me/dreamiurgdmitry.guyvoronsky@gmail.com@dreamiurg

×