Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automated virtual test environments with Vagrant

Robin Müller
September 18, 2013

Automated virtual test environments with Vagrant

How to automate the creation of virtual test environments with Vagrant for Magento. The talk as presented at the Magento Developers Paradise 2013 at Mallorca. There is also a github repository with a complete example at https://github.com/RobM84/devparadise-vagrant/

Robin Müller

September 18, 2013
Tweet

More Decks by Robin Müller

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. Still some issues •  Distribution to other developers •  Huge

    VMs •  No version control of configuration 9
  4. 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
  5. 11

  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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