25
Keep calm and vagrant up (ok, clear the cache) DrupalSH Meetup June, 19th 2013 Shanghai, China Daniel Lopes http://dgo.to/@dscl

Keep calm and vagrant up

Embed Size (px)

DESCRIPTION

I would like to show you guys how easy is it to create a new VM from a base Ubuntu, configure and pack it again so you can distribute to your developers and also to the community. Speed up the initial setup and have a homogeneous dev environment within your team!

Citation preview

Page 1: Keep calm and vagrant up

Keep calm and vagrant up(ok, clear the cache)

DrupalSH MeetupJune, 19th 2013Shanghai, China

Daniel Lopeshttp://dgo.to/@dscl

Page 2: Keep calm and vagrant up

WAIT!

vagrant what ???

Page 3: Keep calm and vagrant up

NOT SO FAST...

Page 4: Keep calm and vagrant up

1. Who am I?

2. What is vagrant?

3. Motivations

4. Common vs. Virtualized environments

5. Boxes

6. Provisioning

7. Other points (hands-on)

8. Useful links

First, our agenda…

Page 5: Keep calm and vagrant up

Daniel Lopes

Brazilian Software Architect living in China since dez/2011

Working with PHP since 1999 (php3) and with Drupal since 2009 (Drupal 6)

Drupal Translator and Reviewer for the Brazilian Portuguese team since 2010

http://dgo.to/@dsclhttp://www.linkedin.com/in/danielsclhttp://www.facebook.com/danielscl

Who am I?

Page 6: Keep calm and vagrant up

What is vagrant?

Vagrant is a tool for building complete development environments.

With an easy-to-use workflow and focus on automation, Vagrant

lowers development environment setup time, increases

development/production parity, and makes the "works on my

machine" excuse a relic of the past.

Page 7: Keep calm and vagrant up

Create and configure lightweight, reproducible, and portable development environments.

- vagrantup.com

Page 8: Keep calm and vagrant up

Motivations…

Setting up a fully configured environment for the Drupal Global Training Day attendees to work on as fast as possible and as effortless as possible

Anyone, technical or non-technical people, should be able to set it up by following a step-by-step tutorial

The solution should be small and lightweight

But it should remain useful after the training

Page 9: Keep calm and vagrant up

Real motivations…

I heard a lot about Vagrant for development and even for production server, and I was looking for an opportunity to use it!

Common ones: ● Upper-case vs. Lower-case● Windows line break vs. Unix-like line break● / vs. /my-project● Different versions of the software (L|W|M)AMP

I am tired of having infrastructure related issues within my teams and projects.

I want to have an homogenous configuration among my development team.

The initial environment setup for new developers takes too long to be done.

Page 10: Keep calm and vagrant up

Common Dev environment

Drupal itself runs over a web server (usually, Apache) with PHP on it and a database (usually, MySQL). And all of them can be running on Linux, Windows or MacOS.

There are a few installer to help you to configure this in your computer like:

For Windows: WAMP - http://www.wampserver.com/en/

For MacOS: MAMP - http://www.mamp.info/en/index.html

For Linux? Come on, you have it already by default...

Page 11: Keep calm and vagrant up

Virtualized Dev environment

The developer needs to simply load a VM (Virtual Machine) based on Ubuntu using Vagrant and Virtualbox so you have everything running very fast and almost effortless.

Required downloads:

Virtualbox 4.2+: https://www.virtualbox.org/wiki/Downloads

Vagrant 1.2.2: http://downloads.vagrantup.com/tags/v1.2.2

Ubuntu 12.04 box: http://files.vagrantup.com/precise32.box

Page 12: Keep calm and vagrant up

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.

Boxes are provider-specific.Providers are the virtualization tools which are supported by vagrant.

So you must obtain the proper box depending on what provider you're using, like:

- Virtualbox, which is out-of-the-box in the open-source version;- VMWare. vagrant paid version (http://www.vagrantup.com/vmware);- and even AWS (https://github.com/mitchellh/vagrant-aws).

Page 13: Keep calm and vagrant up

$ vagrant box add base http://files.vagrantup.com/precise32.box$ vagrant init$ vagrant up

This is the name of your box.

Always use 'base' for your first one.

Page 14: Keep calm and vagrant up

Vagrantfile

The only configuration file needed by vagrant to work.

It defines the box that the VM will run, as well as several other configuration like:

● config.vm.box_url: URL from where the box can be downloaded.

● config.vm.guest: defines the OS that the VM is running.

● config.vm.network: general network configuration. (details later)

● config.vm.provider:the provider software or platform for this VM.

● config.vm.provision: how is the VM going to be provisioned.

● config.vm.synced_folder: folder to be shared between the host and the VM.

Page 15: Keep calm and vagrant up

Provisioning

Provisioning is the action that allows you to install/remove/update software and add or alter any kind of configuration into the VM system while getting it up.

Vagrant uses 6 different ways of provisioning, which are:

● Shell script● Ansible (YAML)● Chef Solo● Chef Client● Puppet apply (serverless)● Puppet agent

But I will show only 2 of them:● Shell script● Puppet apply (serverless)

Page 16: Keep calm and vagrant up

Provisioning with Shell Script

This is pretty straight-forward shell scripting.

You can use it in-line and also create an external file that will be pushed to the VM during the process of getting this up.

Heads-up!Keep in mind that every time you hit vagrant up or vagrant reload, this script will be executed. So care about the execution flow of the script commands (if-else, loops, etc)

Page 17: Keep calm and vagrant up

Provisioning with Puppet

Puppet is a complete server provisioner that allows you to deeply manage any configuration within your server. You can even control deployments using it.

With Vagrant it is used to have a better way to manage the VM configuration and installed software.

Puppet have a lot of modules that can be used to add new features to it. Find more about it at: https://forge.puppetlabs.com/

Page 18: Keep calm and vagrant up

Network

Vagrant allows you to map ports used by services from inside the VM to port numbers in the host machine.By default, it suggests you to use port number over 2200.

It also allows you to use private network, which can use IPs that are only accessible from the host machine.In case you use a private network IP, we'll be able to use ANY port number in the forwarded_port option.

Page 19: Keep calm and vagrant up

Synced folders

Vagrant allows you to easily map folders from the host machine (physical) to the guest VM.

Great way to keep using your current local projects` files instead of pushing everything to inside the VM.

In the following example you can see a way to replace Apache's default docroot ( /var/www ) with your local directory for projects (../projects ).

Page 20: Keep calm and vagrant up

Synced folders

HEADS UP!

● Note that the local directory is being referenced through a relative path. For this you should consider the directory where the Vagrantfile is as the current directory, then navigate any way you like;

● When dealing with Windows host machines, keep the Vagrantfile and the folder you want to sync in the same partition (e.g.: C: or D:).

Page 21: Keep calm and vagrant up

Packing and Distributing

Packing means creating new box files from a machine that is currently present in your system.

You can easily pack new boxes from a your current machine using:

$ vagrant package [vm-name] –output desired-name.box

There are other option for this command to allow you, for instance, pack a Vagrantfile as part of your new box file.

Page 22: Keep calm and vagrant up

Packing and Distributing

Distributing means making the box file that you've just created available to your team or to anyone over the Internet.

You can push it to github, Dropbox or any other place of your taste, and then send a Pull request to Vagrantbox.es so you can get this added to their list.

Page 23: Keep calm and vagrant up

More about boxes...

If you want to, you can even create a new ones from scratch with Veewee (https://github.com/jedi4ever/veewee)

From scratch means getting your favorite OS, favorite apps and so on, and put it together.

How to use Veewee?

Read! http://github.com/jedi4ever/veewee/blob/master/doc/vagrant.md

Watch! http://www.youtube.com/watch?v=3vaLTVkKCPI

Page 24: Keep calm and vagrant up

Useful links

Vagrant docs: http://docs.vagrantup.com/v2/

Vagrant boxes: http://vagrantbox.es

Veewee: https://github.com/jedi4ever/veewee

Aegir-up: https://drupal.org/project/aegir-up

Puppet docs: http://docs.puppetlabs.com/

Puppet modules: https://forge.puppetlabs.com/

Page 25: Keep calm and vagrant up

THANKS A LOT FOR

YOUR TIME