powering development and testing environments with vagrant
TRANSCRIPT
![Page 1: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/1.jpg)
Powering Development and Testing Environments
with Vagrant
Coen Jacobs / @CoenJacobs at
WordCamp Norway 2014 !
#WCNorge
![Page 2: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/2.jpg)
Coen Jacobs@CoenJacobs
!http://coenjacobs.me
!WooThemes / WooCommerce
![Page 3: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/3.jpg)
Powering Development and Testing Environments
with Vagrant
![Page 4: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/4.jpg)
Vagrant
![Page 5: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/5.jpg)
![Page 6: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/6.jpg)
![Page 7: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/7.jpg)
Problem at hand
![Page 8: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/8.jpg)
Get someone started on your project
![Page 9: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/9.jpg)
![Page 10: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/10.jpg)
• “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?”
Let’s get you up and running…
![Page 11: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/11.jpg)
Bring order to chaos
![Page 12: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/12.jpg)
Three common ways to do thisand all three are horrible…
![Page 13: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/13.jpg)
1. Setup script
![Page 14: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/14.jpg)
1. Setup script
• Special maintenance!
• Different to production!
• Windows or Linux?
![Page 15: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/15.jpg)
2. The über README
![Page 16: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/16.jpg)
2. The über README
• Extremely prone to user error!
• Unlikely to keep it up to date!
• Very time consuming!
• Windows or Linux?
![Page 17: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/17.jpg)
3. “Good luck, have fun”
![Page 18: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/18.jpg)
3. “Good luck, have fun”
• Extremely prone to user error!
• Extremely time consuming!
• Extremely frustrating!
• Your developer will hate you…
![Page 19: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/19.jpg)
Downsides• Not repeatable
• Not verifiably correct
• Not isolated
• Difficult to understand
• Slow
![Page 20: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/20.jpg)
![Page 21: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/21.jpg)
![Page 22: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/22.jpg)
What is Vagrant?
![Page 23: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/23.jpg)
“A tool for creating, managing and distributing portable development environments”
- Mitchell Hashimoto (creator of Vagrant)
![Page 24: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/24.jpg)
What is Vagrant?
• Command line tool
• Creates virtual machines
• Handles networking and shared folders
• Supports provisioning
![Page 25: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/25.jpg)
What problems does it solve?
• Repeatable & verifiably correct
• Isolated
• Understandable
• As fast as possible
![Page 26: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/26.jpg)
What problems does it solve?
• Works on Mac, Windows and Linux
• Works with VirtualBox, VMware and many more
![Page 27: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/27.jpg)
How does it work then?It’s magic, it really is…
![Page 28: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/28.jpg)
“Vagrant reads a Vagrantfile and builds a virtual machine based on a template called a box”
- Mitchell Hashimoto (creator of Vagrant)
![Page 29: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/29.jpg)
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
![Page 30: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/30.jpg)
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
![Page 31: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/31.jpg)
Virtual machine
• Isolated environment
• Any operating system
• Any installed software
• Project specific configuration and versions
![Page 32: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/32.jpg)
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
![Page 33: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/33.jpg)
Boxes
• Pre-installed OS
• May contain pre-installed software
• Custom boxes can be made
![Page 34: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/34.jpg)
Provisioning
![Page 35: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/35.jpg)
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
![Page 36: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/36.jpg)
Provisioning• Shell
• Ansible
• Chef
• Puppet
• Docker
• Salt
![Page 37: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/37.jpg)
ProvidersEnabling Vagrant to do its job
![Page 38: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/38.jpg)
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
![Page 39: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/39.jpg)
Providers• VirtualBox
• VMware
• AWS
• Rackspace
• Digital Ocean and many more…
![Page 40: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/40.jpg)
Change providers dynamically
vagrant up --provider=vmware_fusion
vagrant up --provider=digital_ocean
![Page 41: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/41.jpg)
Does this really make a developers life easier?
![Page 42: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/42.jpg)
YES!
![Page 43: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/43.jpg)
Old situation
• Setup script
• The über README file
• “Good luck, have fun” or any other manual way of configuring…
![Page 44: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/44.jpg)
![Page 45: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/45.jpg)
Vagrant is more like…
![Page 46: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/46.jpg)
Get started with a Vagrant project
git clone repository.git folder!cd folder!vagrant up
![Page 47: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/47.jpg)
![Page 48: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/48.jpg)
What did Vagrant do in the background?
![Page 49: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/49.jpg)
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
![Page 50: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/50.jpg)
Your new VM is ready
vagrant ssh
vagrant halt
vagrant destroy
![Page 51: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/51.jpg)
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
![Page 52: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/52.jpg)
From development and testing to production
Using Vagrant to its full potential
![Page 53: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/53.jpg)
Vagrantfile in version control
• Commit your Vagrantfile
• Share it with all developers
• Commit a change, all developers benefit
![Page 54: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/54.jpg)
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
![Page 55: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/55.jpg)
… and this is only the beginning
![Page 56: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/56.jpg)
Advanced use casesNow we’re talking!
![Page 57: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/57.jpg)
Plugin testing
• Stable version
• Development version
• Combine those two on stable/dev WordPress
• Four local websites per plugin
![Page 58: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/58.jpg)
Multiple PHP version testing
• One Vagrantfile
• Multiple machines
• Different PHP versions
• One shared set of files
• One databasehttp://wordpress.org/about/stats/
![Page 59: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/59.jpg)
Integrate useful tools
• WP-CLI
• Xdebug
• WebGrind
• REDIS
• Memcache
• Your own dotfiles
![Page 60: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/60.jpg)
All going a little too fast?No worries
![Page 61: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/61.jpg)
Vagrant has great documentation
• http://docs.vagrantup.com/v2/
• Plenty of examples
• Great pointers to providers and provision resources
• Vagrant is the latest trend
![Page 62: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/62.jpg)
Varying Vagrant Vagrants
![Page 63: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/63.jpg)
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, PHP-FPM, Memcache, Xdebug, Imagemagick, PHPunit, Composer, NodeJS, Grunt, WebGrind and much, much more, all on one Ubuntu 12.04 VM.
![Page 64: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/64.jpg)
Let’s make the world a better place for developers
!
Start using Vagrant
![Page 66: Powering Development and Testing Environments with Vagrant](https://reader035.vdocuments.site/reader035/viewer/2022062702/554a3319b4c90526578b551b/html5/thumbnails/66.jpg)
Photo credits1. 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/