As a developer, one of the most tedious and annoying tasks I run into is trying to set up my development environment. I recently just switched from Windows to Mac and found that getting my Mac up and running as a development box was actually harder than you would think given that Mac’s essentially run on Unix and come with an Apache server built in. Once you start digging in, you’re faced with a lot of choices. There’s Macports, there’s Homebrew, there’s Xcode, there seemed to be a million things I needed to wade through to just get a simple PHP stack up and running. On top of all that, all of these options required that I install a bunch of software packages that made (what I considered) some pretty intrusive changes to my shiny new MacBook Air.
After spinning my wheels on it for a while, I finally heard about a great tool called Vagrant and haven’t looked back since. Vagrant is a command-line tool that lets you download, install, and start using a new virtual server in just a couple minutes–and it even works in PCs! Vagrant works by helping you automate the creation of new VirtualBox servers. Vagrant allows you to:
- Create virtualized Linux or Windows servers
- Run custom build/installation scripts inside the virtual servers when they are created to automatically install any custom software you might need like PHP, Apache, or MongoDB
- Access the server through SSH giving you full shell access
- Share files between your “host” OS and the virtualized OS, which allows your IDE running on your machine to get at project files living on the virtual server
- Access a web server running on the virtualized server in your machine’s browser via a forwarded port like 8080
All of this is great stuff for developers, but what makes this even better is that you can use build tools like Puppet and Chef Solo to automate the creation of your server to perfectly mimic your company’s own development or production environments. This means that your ops team can take the same server provisioning scripts they are already using for building out new servers and open them up to developers who what to provision these servers on their local machines for testing.
Furthermore, since all of this is done with plain old Ruby scripts everything can be checked into version control. You can check in all your Puppet and Chef Solo server provisioning scripts along with the Vagrant configuration files and distribute them via your company’s source control system. This makes it simple to onboard new developers and to propagate server upgrades across all the developers in your team.
Time permitting, I hope to provide some more concrete examples here of how you would use Vagrant and specifically the Chef Solo provisioner in later posts.