What is Vagrant?
- A tool for developers
- A VM management tool
- Automate the setup of your development environment
New starter
- Someone joins your project...
- They pick up their laptop...
- Then spend the next 1-2 days following instructions on setting up their environment, tools, etc.
New starter
- Someone joins your project...
- They pick up their laptop...
- Then spend the next 10 minutes running a script which sets their environment up for them.
Prerequisites
- Virtualbox
- Vagrant
- Both Virtualbox and Vagrant have great, simple installation instructions.
Follow these steps once Virtualbox and Vagrant are installed.
Setting up the box
Getting set up
- Add a Vagrant box
- Create the VM
- Configure the VM
- Set up your project environment
Adding a box*
*What's a box? We'll cover that shortly.
Setting up Ubuntu Precise
- vagrant box add ubuntu-precise http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box
- vagrant init ubuntu-precise
- vagrant up
Adding the box
- vagrant box add ubuntu-precise http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box
Adding the box
- vagrant box add ubuntu-precise http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box
Adding the box
- vagrant box add ubuntu-precise http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box
Adding the box
Getting set up
- Add a Vagrant box
- Create the VM
- Configure the VM
- Set up your project environment
Start with a working dir.
- mkdir -p ~/Development/awesome_project
- cd ~/Development/awesome_project
Initialise the Vagrant setup
- vagrant init ubuntu-precise
Launch the Vagrant VM
Launch the Vagrant VM
Your vagrant VM is built and ready to use.
Getting set up
- Add a Vagrant box
- Create the VM
- Configure the VM
- Set up your project environment
SSH to the VM
Install all the things !
- sudo apt-get install curl apache2 avahi-daemon avahi-discover avahi-utils gcc git-core libapache2-mod-dnssd make mysql-server samba subversion unzip vim php5 php-apc php5-cli php5-curl php5-dev php5-gd php5-memcache php5-memcached php5-mysqlnd php5-xdebug
- These aren't all essential, but make a good base for a good development environment.
Install all the things !
- sudo apt-get install curl apache2 avahi-daemon avahi-discover avahi-utils gcc git-core libapache2-mod-dnssd make mysql-server samba subversion unzip vim php5 php-apc php5-cli php5-curl php5-dev php5-gd php5-memcache php5-memcached php5-mysqlnd php5-xdebug
Getting set up
- Add a Vagrant box
- Create the VM
- Configure the VM
- Set up your project environment
Create a Drupal setup
- sudo mkdir /srv/awesome_project
- sudo chown vagrant:vagrant /srv/awesome_project
- cd /srv/awesome_project
- git clone git@github.com/example/awesome_project.git htdocs
- mkdir /srv/awesome_project/conf
- touch /srv/awesome_project/conf/httpd.conf
- sudo ln -s /srv/awesome_project/conf/httpd.conf /etc/apache2/sites-available/awesome_project.conf
- sudo ln -s ../sites-available/awesome_project.conf /etc/apache2/sites-enabled
Set up your environment
- mysql -e "GRANT ALL ON *.* TO 'vagrant'@'localhost' IDENTIFIED BY '' WITH GRANT OPTION"
- Add whichever setup instructions are appropriate for your environment
Manual setup is baad, mmkay?
Manual installation is never efficient
Streamlining the setup
A stream-lined setup Option 1 - A magick box.
Start with a customised box
- vagrant box add awesome_project http://boxes.example.com/supercool_drupal_project.box
Start with a customised box
- vagrant box add awesome_project
http://boxes.example.com/supercool_drupal_project.box
A magick box.I'll explain later!
Follow the standard setup
- mkdir -p ~/Development/awesome_project
- cd ~/Development/awesome_project
- vagrant init awesome_project
- vagrant up
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
vagrant@vm-druprecise:~$ ls -l /srv/
total 4
drwxr-xr-x 3 root root 4096 Mar 10 18:28 foo.local
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
vagrant@vm-druprecise:~$ which drush
/usr/local/bin/drush
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
vagrant@vm-druprecise:~$ mysql -e 'show databases';
Database |
1. information_schema |
2. foo_local |
3. mysql |
4. performance_schema |
5. phpmyadmin |
Recap of all those steps
- vagrant box add awesome_project http://boxes.example.com/supercool_drupal_project.box
- mkdir -p ~/Development/awesome_project
- cd ~/Development/awesome_project
- vagrant init awesome_project
- vagrant up
A stream-lined setup
Option 2 - A vagrant config.
Start with a build directory
- mkdir -p ~/Development/awesome_project
- cd ~/Development/awesome_project
Checkout a Vagrant config
- git clone git@github.com/Techito/vagrant_drupal_box.git.
Verify the checkout
Verify the checkout
Verify the checkout
Get Vagrant going
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
vagrant@vm-druprecise:~$ ls -l /srv/
total 4
drwxr-xr-x 3 root root 4096 Mar 10 18:28 foo.local
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
vagrant@vm-druprecise:~$ which drush
/usr/local/bin/drush
Verify what's in the box
- ls /srv/
- which drush
- mysql -e 'show databases;'
vagrant@vm-druprecise:~$ mysql -e 'show databases';
Database |
1. information_schema |
2. foo_local |
3. mysql |
4. performance_schema |
5. phpmyadmin |
Recap of all those steps
- mkdir -p ~/Development/awesome_project
- cd ~/Development/awesome_project
- git clone git@github.com/example/awesome_project.git .
- vagrant up
Automated provisioning
=
super-quick setup
Vagrant Vocabulary
- Virtualbox
An application to run "Virtual machines" on your laptop/desktop.
- Vagrant
An application that automates the setup of VMs.
- Host
The laptop/desktop that runs Virtualbox + Vagrant.
- Guest / Guest VM / Instance
The virtual machine running within the host.
Vagrant Vocabulary
- Mount
A way of sharing files between the host and guest (this is a simplification - search for "disk mount" for a more detailed explanation).
- Provision / Provisioning
Setting up the VM, installing packages, configuring users, etc.
- Box / Base box
A template for a Virtual Machine.
- Vagrantfile
A set of instructions to Vagrant on how to build and configure a VM.
A "magick" pre-packaged box, or a vagrant config structure.
Two approaches
Standard practice
- Start with a base-box of choice.
– Ubuntu, CentOS, Debian...?
– 32 bit vs 64 bit
Standard practice
- Start with a base-box of choice.
– Ubuntu, CentOS, Debian...?
– 32 bit vs 64 bit
- Add a Vagrantfile.
– `vagrant init` will give you a template
Standard practice
- Start with a base-box of choice.
– Ubuntu, CentOS, Debian...?
– 32 bit vs 64 bit
- Add a Vagrantfile.
– `vagrant init` will give you a template
- Configure the Vagrantfile.
– Hostname, network adapters, config paths...
Standard practice
- Start with a base-box of choice.
– Ubuntu, CentOS, Debian...?
– 32 bit vs 64 bit
- Add a Vagrantfile.
– `vagrant init` will give you a template
- Configure the Vagrantfile.
– Hostname, network adapters, config paths...
Great docs at http://vagrantup.com/
Standard practice
- Start with a base-box of choice.
– Ubuntu, CentOS, Debian...?
– 32 bit vs 64 bit
- Add a Vagrantfile.
– `vagrant init` will give you a template
- Configure the Vagrantfile.
– Hostname, network adapters, config paths...
- Add puppet/chef manifests
Standard practice
- Start with a base-box of choice.
– Ubuntu, CentOS, Debian...?
– 32 bit vs 64 bit
- Add a Vagrantfile.
– `vagrant init` will give you a template
- Configure the Vagrantfile.
– Hostname, network adapters, config paths...
- Add puppet/chef manifests
I'll talk briefly on puppet + chef shortly
Magick box vs standard config
Magick
- Simpler for junior developers.
- Puppet/chef config tucked away out of sight.
- Base-box and config stored together in one place.
- Streamlined setup.
Standard
- Standard practice.
- No surprises, everything visible.
- Easily updateable (and version-controllable).
- No special packaging required.
Two approaches: puppet/chef config only, or complete packaging.
Magick box packaging
Packaging practices
☞ Puppet/chef only
- Smaller base-box.
- Requires internet access to build.
- Always fetches latest version of the packages.
☞ Complete packaging
- Larger base-box.
- Ready to go without needing internet access.
- Packages may become out-of-date.
Creating your own base box
Why create a base box?
- More flexibility than puppet/chef alone
- Trusted source
- Specific version of O/S (maybe you really want to run Slackware as your O/S of choice!)
How to create a base box
- Start by creating the VM in Virtualbox* as usual.
- Follow community standards where possible (sizing of VM, disk, RAM, etc).
- Add several Vagrant-specific tools (an SSH key, etc). Instructions on http://vagrantup.com/.
- OR: use Veewee to build it for you.
✽ Vagrant is becoming less Virtualbox-specific, so you may be able to use a different provider, such as VMWare.
Choosing a base box
Puppet or Chef?
- Puppet and Chef do the same thing – automated provisioning:
- Installing packages (apt-get install / yum install)
- Creating users + groups
- Managing config files
- Any provisioning task imaginable(but you might have to write the plugin)
- Both are Ruby applications.
- Both have an active open-source community.
Puppet or Chef?
- How do you choose?
– Is anyone in your team familiar with either of them?
– Do you use any modules/packages/vagrant setups which expect one or the other?
– Can you easily find support (either paid-for or free) in your community?
Puppet or chef resources
Puppet
- The Drupal.org testbots
http://drupal.org/project/drupaltestbot-puppet
- Demo from this talk
https://github.com/Techito/vagrant_drupal_box
- Project Oscar
https://github.com/manarth/oscar
Chef
- Megalodon
https://github.com/msonnabaum/megalodon (native install, rather than VM).
- Drupal Vagrant project
http://drupal.org/project/vagrant
Key resources
- Virtualbox
https://www.virtualbox.org/
- Vagrant
http://vagrantup.com/
- Base-box list
http://www.vagrantbox.es/
- Puppet resources
http://puppetlabs.com/
- Chef resources
http://www.opscode.com/chef/
Other resources
- Drush Vagrant
http://drupal.org/project/drush-vagrant
- Veewee (to build base boxes)
https://github.com/jedi4ever/veewee
- IRC: #vagrant
Beyond Vagrant & dev VMs
- Vagrant is expanding to cover other provisioning tools:
– VMWare Fusion
– ESXi
– Amazon
– ???
- Puppet and Chef can manage your test/stage/CI/production environments too.
- Tools like Cobbler and Satellite can fully-automate the build of new VMs
Vagrant...
- Automates the setup and installation of a local dev VM.
- Create a fully-configured ready-to-go VM in minutes.
- Basic usage doesn't need any new skills.
- Advanced configuration possible with Veewee, Puppet and Chef.
- To get started: download an open-source Vagrant setup, or build your own.
QUESTIONS ??