Docker Powered Rails Testing with Pipelines

The Bitbucket team at Atlassian has released Pipelines, a feature that allows automated tests to be run on a simple Git push or merge request. My favorite part about this is that it’s powered by Docker! It’s yet another awesome use for Docker! If you’re already using Bitbucket for source control and writing automated tests, then there’s very little effort required to get rolling with Pipelines.

At Buccaneer we tend to use RSpec for our BDD testing strategy in our Rails applications. Setting that up to work with Pipelines took under ten minutes. We simply had to add a Docker configuration file to the root of the source repository. Here’s one we are using for an internal service:

# Only use spaces to indent your .yml configuration.
# —–
# You can specify a custom docker image from Docker Hub as your build environment.
image: ruby:2.3.1

– step:
script: # Modify the commands below to build your repository.
– apt-get update
– apt-get install -y build-essential libpq-dev nodejs
– bundle install
– bundle exec rake db:reset RAILS_ENV=test
– bundle exec rake db:migrate RAILS_ENV=test
– bundle exec rake db:seed RAILS_ENV=test
– bundle exec rspec

This installs some dependencies required by our project, then runs some pretty standard Rails commands for database setup / management and finally runs the tests with RSpec.

Once that is all setup every push in Git will trigger a build and run the tests!. We’ve found it very helpful to actually use Bitbucket’s Slack integration to notify us when a build passes testing or doesn’t rather than just relying on the default email notifications

If you want to learn more about how you can solve DevOps like Bitbucket has, please fill out the form on this page to get started with a DevOps blueprint. Also, follow us on Twitter and subscribe to our Youtube channel for more cutting edge tips.