Work has begun on a new couchbase-maven-plugin to interact with a running instance of Couchbase from a Maven build. Read more about how and why here.

We recently started using Couchbase Server at work and came up against a minor inconvenience in the lack of readily available build tools that integrate with Couchbase. We use Maven for our builds, and noted the absence of a plugin to handle interactions with Couchbase as part of our build process. In our particular case, we have a number of integration tests that rely on a running instance of Couchbase to store/retrieve data; and I can think of plenty more reasons why you might want to perform some administrative operations on Couchbase during a build. Having previously used Cassandra (and the cassandra-maven-plugin), we were used to being able to spin up an instance of the store, use it, and shut it down, all as part of the standard Maven build lifecycle. But Couchbase is slightly different in that you can't simply spin up a new instance in the same way as Cassandra (at least, not as far as I can tell).

So we wanted to be able to interact with an already running instance of Couchbase, but provide separate buckets for each build. This avoids having parallel builds stepping on each others' toes and also makes clean-up very simple. Fortunately Couchbase provides a REST API for administrative operations, so I decided to whack together a very basic plugin to handle the minimal cases that we need - creating & deleting buckets. Initially we just used the exec-maven-plugin to execute commands with the couchbase-cli, but that's a little more environment-dependent as it needs the tool to be locally installed, permissions appropriately configured, and a bunch of other stuff that I won't go into here.

Using the Plugin

The plugin is still in a fairly rough form, but it does the job. I'll keep adding features / goals to the plugin if time permits, and please do send feature requests (or just submit them directly to the project) to make this more broadly useful. The couchbase-maven-plugin project is hosted on GitHub and I'm aiming to do the first release very soon (assuming all goes well). I'm just looking for an easy way to deploy site docs somewhere public and then should be ready to go - so if you have any suggestions for this, please let me know. I'm currently thinking of deploying to an Amazon S3 website-configured bucket, but just need to figure out how to get Maven to do that for me.

Here's an example of how you can use the plugin to create & delete a bucket for integration tests:

Supporting Parallel Builds

So one of the things I mentioned at the start was the ability to support parallel builds. Luckily this isn't something we need to handle directly within the plugin, as it's already supported by Maven and your build tool (in my case, Jenkins). Whenever a job executes, Jenkins sets a whole bunch of environment variables that you can use in your Maven build. In this case, we can safely use the BUILD_TAG variable as our bucket name, which isolates the Couchbase data buckets used for each job. You can find a list of the environment variables set by Jenkins here.

I hope this plugin is useful to someone out there. Feel free to fork it, submit pull requests for new functionality, or just use it quietly without anyone knowing. I'll post an update when the first release is available in Maven Central.



Published

06 November 2012

Share

submit to reddit