$30 off During Our Annual Pro Sale. View Details »

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. AUTOMATED VIRTUAL
    TEST ENVIRONMENTS
    WITH VAGRANT
    Robin Müller – @_RobM – 2013-09-18
    1

    View Slide

  2. 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

    View Slide

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

    View Slide

  4. 4
    …and seen that on a dev machine

    View Slide

  5. 5
    What could possibly go wrong?

    View Slide

  6. Classic setup
    6

    View Slide

  7. 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

    View Slide

  8. Solution? Virtualized test environments!
    8

    View Slide

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

    View Slide

  10. 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

    View Slide

  11. 11

    View Slide

  12. 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

    View Slide

  13. 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

    View Slide

  14. 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

    View Slide

  15. 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

    View Slide

  16. 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

    View Slide

  17. 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

    View Slide

  18. 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

    View Slide

  19. 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

    View Slide

  20. 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

    View Slide

  21. 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

    View Slide

  22. 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

    View Slide

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

    View Slide

  24. 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

    View Slide