Powering Development and Testing Environments with Vagrant

2,011 views

Published on

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

No Downloads
Views
Total views
2,011
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
19
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Powering Development and Testing Environments with Vagrant

  1. 1. Powering Development and Testing Environments with Vagrant Coen Jacobs / @CoenJacobs at WordCamp Norway 2014 ! #WCNorge
  2. 2. Coen Jacobs @CoenJacobs ! http://coenjacobs.me ! WooThemes / WooCommerce
  3. 3. Powering Development and Testing Environments with Vagrant
  4. 4. Vagrant
  5. 5. Problem at hand
  6. 6. Get someone started on your project
  7. 7. Let’s get you up and running… • “I just use MAMP, it’s brilliant” • “Tell me what you need and I’ll make a VM” • “My VPS runs a custom compiled LAMP setup” • “A server, what do I need that for?”
  8. 8. Bring order to chaos
  9. 9. Three common ways to do this and all three are horrible…
  10. 10. 1. Setup script
  11. 11. 1. Setup script • Special maintenance! • Different to production! • Windows or Linux?
  12. 12. 2. The über README
  13. 13. 2. The über README • Extremely prone to user error! • Unlikely to keep it up to date! • Very time consuming! • Windows or Linux?
  14. 14. 3. “Good luck, have fun”
  15. 15. 3. “Good luck, have fun” • Extremely prone to user error! • Extremely time consuming! • Extremely frustrating! • Your developer will hate you…
  16. 16. Downsides • Not repeatable • Not verifiably correct • Not isolated • Difficult to understand • Slow
  17. 17. What is Vagrant?
  18. 18. “A tool for creating, managing and distributing portable development environments” - Mitchell Hashimoto (creator of Vagrant)
  19. 19. What is Vagrant? • Command line tool • Creates virtual machines • Handles networking and shared folders • Supports provisioning
  20. 20. What problems does it solve? • Repeatable & verifiably correct • Isolated • Understandable • As fast as possible
  21. 21. What problems does it solve? • Works on Mac, Windows and Linux • Works with VirtualBox, VMware and many more
  22. 22. How does it work then? It’s magic, it really is…
  23. 23. “Vagrant reads a Vagrantfile and builds a virtual machine based on a template called a box” - Mitchell Hashimoto (creator of Vagrant)
  24. 24. Vagrantfile “The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines.” http://docs.vagrantup.com/v2/vagrantfile/index.html
  25. 25. Vagrantfile Vagrant::configure("2") do |config|! ! config.vm.box = "precise32"! ! config.vm.box_url = “http://.../precise32.box”! ! config.vm.hostname = "vagrant.localhost"! ! ! config.vm.network :private_network, ip: "192.168.99.100"! end
  26. 26. Virtual machine • Isolated environment • Any operating system • Any installed software • Project specific configuration and versions
  27. 27. Boxes “Boxes are the skeleton from which Vagrant machines are constructed. They are portable files which can be used by others on any platform that runs Vagrant to bring up a working environment.” http://docs.vagrantup.com/v2/boxes.html
  28. 28. Boxes • Pre-installed OS • May contain pre-installed software • Custom boxes can be made
  29. 29. Provisioning
  30. 30. Provisioning “Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process.” http://docs.vagrantup.com/v2/provisioning/index.html
  31. 31. Provisioning • Shell • Ansible • Chef • Puppet • Docker • Salt
  32. 32. Providers Enabling Vagrant to do its job
  33. 33. Providers “While Vagrant ships out of the box with support for VirtualBox, Vagrant has the ability to manage other types of machines as well. This is done by using other providers with Vagrant.” https://docs.vagrantup.com/v2/providers/index.html
  34. 34. Providers • VirtualBox • VMware • AWS • Rackspace • Digital Ocean
 
 and many more…
  35. 35. Change providers dynamically vagrant up --provider=vmware_fusion vagrant up --provider=digital_ocean
  36. 36. Does this really make a developers life easier?
  37. 37. YES!
  38. 38. Old situation • Setup script • The über README file • “Good luck, have fun”
 
 or any other manual way of configuring…
  39. 39. Vagrant is more like…
  40. 40. Get started with a Vagrant project git clone repository.git folder! cd folder! vagrant up
  41. 41. What did Vagrant do in the background?
  42. 42. The vagrant up command • Check if the box is already downloaded • If not, download the box • Start the VM • Set up synced folders • Set up networking • Start provisioning
  43. 43. Your new VM is ready vagrant ssh vagrant halt vagrant destroy
  44. 44. Your new VM is ready • Some examples of what ‘ready’ means: • Nginx installed • PHP installed • MySQL installed • WordPress installed • Database imported • wp-config.php file set up
  45. 45. From development and testing to production Using Vagrant to its full potential
  46. 46. Vagrantfile in version control • Commit your Vagrantfile • Share it with all developers • Commit a change, all developers benefit
  47. 47. Share the provisioning • Provisioning files into version control as well • Production server shares the provisioning files • • Use parameters/flags for differences Change one, all environments will change
  48. 48. … and this is only the beginning
  49. 49. Advanced use cases Now we’re talking!
  50. 50. Plugin testing • Stable version • Development version • Combine those two on stable/dev WordPress • Four local websites per plugin
  51. 51. Multiple PHP version testing • One Vagrantfile • Multiple machines • Different PHP versions • One shared set of files • One database http://wordpress.org/about/stats/
  52. 52. Integrate useful tools • WP-CLI • REDIS • Xdebug • Memcache • WebGrind • Your own dotfiles
  53. 53. All going a little too fast? No worries
  54. 54. Vagrant has great documentation • http://docs.vagrantup.com/v2/ • Plenty of examples • Great pointers to providers and provision resources • Vagrant is the latest trend
  55. 55. Varying Vagrant Vagrants
  56. 56. Varying Vagrant Vagrants • https://github.com/10up/varying-vagrant-vagrants • Ready to use Vagrant setup • Really easy to expand • Quickly launch new local development websites • Automatically installs: WP-CLI, Nginx, MySQL, PHPFPM, Memcache, Xdebug, Imagemagick, PHPunit, Composer, NodeJS, Grunt, WebGrind and much, much more, all on one Ubuntu 12.04 VM.
  57. 57. Let’s make the world a better place for developers ! Start using Vagrant
  58. 58. Questions? Now, or come find me later! ! @CoenJacobs http://coenjacobs.me
  59. 59. Photo credits 1. http://www.flickr.com/photos/tinali778/2947963220/ 2. http://www.flickr.com/photos/naan/2948047370/ 3. http://www.flickr.com/photos/riebart/4466482623/ 4. http://www.flickr.com/photos/55915190@N00/2302651444/ 5. http://www.flickr.com/photos/l2f1/4895151918/ 6. http://www.flickr.com/photos/basykes/490907537/ 7. http://www.flickr.com/photos/whiskeytango/2098182380/ 8. http://www.flickr.com/photos/chr1sp/5942681564/ 9. http://www.flickr.com/photos/5wa/6109494115/ 10.http://www.flickr.com/photos/msimdottv/4339697089/

×