You NEED to start using Vagrant for Web Development.

Vagrant is an exceptionally useful tool for pretty much every web development project, and rather than provide you with a step by step guide to using it (there are much better, more educated, resources out there for that), I’m going to my best to make a solid case for why you should be using it. There are very good reasons to be jumping on this train whether you’re in development, design or management, everyone can benefit from this.

First though, what is Vagrant? It’s a tool for building development environments in a completely automated fashion. It takes the process of setting up your environment, installing databases, interpreters, web servers and so on, and completely automates it within a sandbox. Once you’ve created your configuration files, you can get a development setup onto ANY computer by installing VirtualBox, Vagrant, and then running a single entry on the command line.

It’s easier to show than tell, so lets take a look at some ‘early days’ config files for Pomodoro Go, a side project I’m working on. If this kind of thing is not your bag (it’s developer focussed), skip past all this to find out the key advantages to all this trouble. Here’s the config:

Vagrant.configure("2") do |config|
  config.vm.box = "precise64chef"
  config.vm.box_url = "http://grahamc.com/vagrant/ubuntu-12.04-omnibus-chef.box"

  config.vm.network :forwarded_port, guest: 9000, host: 9010
  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = [
      "deployment/cookbooks",
    ]
    chef.add_recipe "pomodorogo"

     chef.json = {
       "postgresql" => {
         "password" => {
           "postgres" => "postgresql's_password",
           "vagrant" => "vagrant's_password"
         }
       }
     }
  end
end

This is the base of Vagrant’s configuration. When you run Vagrant, it starts off with a ‘box’, which is basically an image of an operating system and forms the base of your config. The box url means that Vagrant will download it automatically if required. Once the box is set up, you can ‘provision’ it, installing required software, creating databases, users, and so on.

In this case I’m using Chef, an automated configuration manager, but you can also use basic shell scripts when you’re getting your feet wet.  You’ll move on pretty quickly to something like Chef or Puppet though, because they are much easier to work with in a detailed configuration. Most of the detail of this configuration is in the recipe `pomodorogo`, but I think it’d be a bit heavy for this blog post. Once provisioning is complete, your box is ready to go, up and running.

From here you can SSH into the box using the command `vagrant ssh` and do whatever you like. In additionn any web servers you run will connect to you local machine through port forwarding, and the development folder gets synchronised with the box, so you can work on the project locally once the server is running.

Why Bother with Vagrant? Reasons.

That’s a pretty quick look at it all, here’s the list of reasons WHY this is worth the trouble.

  • Designers don’t need developers to spend a day setting up their machine. A proper configuration means a single command will build up everything they need to run the project on their machine while they go grab a coffee.
  • New People can be brought into the project with much less friction as the Vagrant configuration is kept with your version control system. This is especially valuable for very small teams or solo developers looking to bring in new people, where everyone’s time is at a premium.
  • Deployment configuration is upfront in the Vagrant process, so when it’s time to take your project live your setup files will be up to the task with a little bit of tweaking. This knowledge and confidence will greatly smooth any launch you need to do.
  • Testing can be made much closer to your production setup, but in a development scenario, which again makes sure your deployment process will be a much nicer experience.
  • Developers in teams will spend a lot less time working on ‘it worked on my machine’ issues, so they’ll be able to devote more time to adding value, not chasing ghosts.

Please give it a try, the learning curve is entirely worth the effort as the potential gains to your projects are enormous.

Advertisements