Stretchy is an ActiveRecord-esque query builder for Elasticsearch. It’s not stable yet (hence the <1.0 version number), and Elasticsearch has been moving so fast it’s hard to keep up. The major change in 2.0 was eliminating the separation between queries and filters, a major source of complexity for the poor gem.

For now my machine needs Elasticsearch 1.7 for regular app development. To update the gem for 2.0 2.1, I’d need to have both versions of Elasticsearch installed. While I could potentially do that by making a bunch of changes to the config files set up by Homebrew, I thought it would be better to just run the specs on a virtual machine and solve the “upgrade problem” indefinitely.

Docker looked great because I wanted to avoid machine setup as much as possible. I’ve used Vagrant before, but it has its own configuration steps beyond just “here’s the Dockerfile.” I already have boot2docker docker-machine installed and running for using the CodeClimate Platform™ beta, and I didn’t want to have multiple virtual machines running simultaneously, eating RAM and other resources. Here’s the setup:

  • Docker lets you run virtual machines inside “containers,” using a few different technologies similar to LXC
  • boot2docker docker-machine manages booting virtual machine instances which will run your Docker containers. I’m using it to keep one virtualbox machine around to run whatever containers I need at the moment
  • fig docker-compose lets you declare and link multiple containers in a docker-compose.yml file, so you don’t need to manually run all the Docker commands
  • The official quickstart guide for rails gives a good run-down of the tools and setup involved.

It’s a bit of tooling, but it really didn’t take long to get started; maybe an hour or two. Once I had it up and running for the project, I just modified the docker-compose.yml on my new branch. I had to do a bit of fiddling to get Compose to update the elasticsearch image from 1.7 to 2.1:

# modify the docker-compose.yml to update the image version, then:
docker-compose stop elastic
docker-compose pull elastic
docker-compose rm -f -v elastic
docker-compose run web rpsec # boom! builds the machines and runs specs

Once there, the specs started exploding and I was in business. Let the updates begin! After that, just a matter of pestering our CI provider to update their available versions of Elasticsearch so the badge on the repo will look all nice and stuff.