Slide 1

Slide 1 text

AUTOMATED VIRTUAL TEST ENVIRONMENTS WITH VAGRANT Robin Müller – @_RobM – 2013-09-18 1

Slide 2

Slide 2 text

Goals Answers to the following questions: •  What is Vagrant? •  How does it work? •  How can it be used with Magento? •  Are there any known issues? •  Which problems are solved by Vagrant? 2

Slide 3

Slide 3 text

3 100% certified We’ve all heard this before…

Slide 4

Slide 4 text

4 …and seen that on a dev machine

Slide 5

Slide 5 text

5 What could possibly go wrong?

Slide 6

Slide 6 text

Classic setup 6

Slide 7

Slide 7 text

Classic setup - the issues •  No isolated environment •  Multiple servers running on the same machine •  Other software running •  Not reproducible •  The system & configuration grew over months or years •  Which version was used for testing? •  Setting it up on a new developers machine is pain 7

Slide 8

Slide 8 text

Solution? Virtualized test environments! 8

Slide 9

Slide 9 text

Still some issues •  Distribution to other developers •  Huge VMs •  No version control of configuration 9

Slide 10

Slide 10 text

That’s where Vagrant comes into play •  Tool for building complete development environments •  Focus on automation •  Configuration can be checked into source control •  Uses VirtualBox and Chef or Puppet 10

Slide 11

Slide 11 text

11

Slide 12

Slide 12 text

Vagrant •  Started in 2010 •  Uses different providers •  VirtualBox (free) •  VMware (commercial) •  AWS •  Provisioning with Chef, Puppet or Shell scripts •  Shared folders between host and guest •  SSH access •  Port forwarding 12

Slide 13

Slide 13 text

Getting started •  Install VirtualBox => virtualbox.org •  Install Vagrant => vagrantup.com 13 $ vagrant box add precise64 http:// files.vagrantup.com/precise64.box $ vagrant init precise64 $ vagrant up

Slide 14

Slide 14 text

Getting started •  What happened? •  Added and downloaded a vagrant base box with the alias precise64 •  Created a basic configuration (Vagrantfile) •  Started a virtual environment with the configuration from the Vagrantfile •  On the first vagrant up a copy of the box is created and provisioned •  Where is my box? •  It’s running in headless mode 14

Slide 15

Slide 15 text

Vagrantfile 15 Vagrant.configure("2") do |config| config.vm.box = "precise64” config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.synced_folder "./data", "/vagrant_data" # ... # config.vm.provision :chef_solo do |chef| # chef.cookbooks_path = "../my-recipes/cookbooks" # chef.roles_path = "../my-recipes/roles" # chef.data_bags_path = "../my-recipes/data_bags" # chef.add_recipe "mysql" # chef.add_role "web" # # # You may also specify custom JSON attributes: # chef.json = { :mysql_password => "foo" } # end end

Slide 16

Slide 16 text

Vagrantfile •  config.vm.box •  The name of your box •  config.vm.box_url •  Download URL of the box •  config.vm.network •  Network configuration (Port forwarding, Private vs. public networks) •  config.vm.synced_folder •  Synced folders between your box and the host •  config.vm.provision •  The provisioners 16

Slide 17

Slide 17 text

Commands & usage •  vagrant init •  Creates a Vagrantfile in the current directory •  vagrant up •  Creates and configures guest machines defined in the Vagrantfile •  vagrant halt •  Shutdown guest machine •  vagrant destroy •  Shutdown and delete guest machine •  vagrant suspend / vagrant resume •  vagrant ssh •  SSH into running machine 17

Slide 18

Slide 18 text

Structure •  Host (developer machine) •  Code (including Vagrantfile) •  Vagrant •  Virtualbox •  Client (Vagrant box) •  Test environment •  Code is linked into the client using a shared folder 18

Slide 19

Slide 19 text

Dos & Don’ts •  DO •  Create your own base boxes if you need some special linux distribution •  Configure it using the provisioners •  DON’T •  Install everything in the base box •  Use vagrant in production 19

Slide 20

Slide 20 text

Known issues with shared folders •  Shared folders are slow if you have many files being accessed •  Official advise •  Windows Host: Shared folder performance should be okay •  Linux/Mac OS Host: Use NFS •  Inofficial •  Windows Host: Performance is low •  Linux/Mac OS Host: NFS is okay •  Workarounds •  Modman •  Git hooks 20

Slide 21

Slide 21 text

Scenarios •  Agencies or Freelancers developing for multiple clients •  Updating an old project for a customer •  Fast growing development teams •  Huge software stack needed for testing 21

Slide 22

Slide 22 text

Try it •  Repository on github with everything needed to start •  Branch “quickstart” with all Chef recipes •  How To •  Download & install VirtualBox •  Download & install Vagrant •  Download Magento •  Extract Magento into ./magento directory •  Do a vagrant up from the base folder 22

Slide 23

Slide 23 text

More information 23 @_RobM https://github.com/RobM84/devparadise-vagrant/ https://speakerdeck.com/robm84

Slide 24

Slide 24 text

Sources / worth reading •  http://www.codinghorror.com/blog/2007/03/the-works-on- my-machine-certification-program.html •  http://www.vagrantup.com/about.html 24