Propeople Blog

A regular dose of fresh news, events, products, Drupal development resources and more.

November 23, 2012

Complex development environment simplified with Vagrant

Open source is definitely a mainstream nowadays. Huge corporate systems are implemented using it. The complexity of the environment is growing fast. Currently we do not have a project that does not involve using multiple web nodes, reverse proxies, memcache, Apache Solr, Sphinx, Multi-domain setup and many more software elements which turn creating good development environments into a good challenge.
Let's say project X is running only on PHP 5.2 but project Y requires 5.3 and developer must upgrade/downgrade PHP version every time he needs to make a switch or install new software or reproduce a bug that only happens on live environment where we have 50 domains available. The process obviously needed an improvement and the solution was found:
1. Create the same development environments for developers that use different operating systems – Windows, UNIX. This makes the process of building automate tools for environment synchronization much easier.
2. Simply project installation for the developers and thus minimize the time for adding new developer to the project.
3. Remove version problems and thus allowing the same developer to work on multiple projects ( very important when supporting large base of projects).
4. Reproduce live environment which makes catching tricky bugs much easier and makes the "works on my machine" excuse irrelevant.
5. Force automates deployment of the development features.
Why Vagrant:
1. Easy to use.
2. Known in Drupal community (there are modules that helps in certain Vagrant tasks such as this one).
3. Open source.
4. Well documented and supported.
Step 1:
- Download and install the latest version of VirtualBox if you use Windows. Download either the lastest version of VirtualBox or whatever you have in the package system for Linux/OS X.
- The above also applies to the installation of Vagrant.
- We have created our own vagrant plugin that we use to setup complex network environments i.e. several servers or multiple domains. The nodes are added into local host file and Virtual Machines are available into local computer network. The plugin is not public now as it has some specific setup compatible with our network.
Create some directory structure for the Vagrant files for the different projects. These are one time operations.
Step 2: 
Download the base VirtualBox image with the command: vagrant box add centos64 (your_vagrant_images_storage/ This machine contains the OS specific version based on the projects you need to work with.
Step 3 (Provisioning): 
Next step is to setup all used software on the VM including Drupal related part. There are two popular systems at the moment, called Puppet and Chef. Both have been around for years, but have started becoming a lot more popular with the increase of the DevOps development method. The provision files are handled in git and next step is to pull the files from the project repository.
Step 4 (Start environment): 
Just execute vagrant up and the magic will start happening, VMs setup will start and depending on the complexity of the environment it will be ready in 30 minutes to 1 hour and you have your developers ready to produce effective solutions.
Working with Vagrant: 
Starting and stopping Vagrant
You have three options for stopping the machines:
- vagrant destroy: this will completely remove the virtual machines and all your custom information on them. The next time you run vagrant you will start with the base virtual image + what puppet, drush and shell scripts will provision for you. This means that you need to prepare drush installation for your features and not setup them manually.
- vagrant halt: this will shutdown the virtual machines free system resources but keep your environment the same as you left it.
- vagrant suspend: this will save the state of the virtual machines (something like hibernation) and will still use some resource on your machine.
You start the machines with vagrant up. All of the above commands can be succeeded by the the machine name for multi-VM projects if you only want to trigger the action for a single virtual machine.

0 Responses to this post