Container42 Stuff I find interesting

Twitter GitHub

DockerHub in dev-test Workflow

When DockerHub was announced there was a really handy feature added that you may have missed: Webhooks.

With DockerHub you can setup a webhook to call out to an external service once a successful push of a particular image is made (this includes completion of automated builds).

This makes for a nice addition to an existing CI/CD workflow.

The basic idea is this:

  1. Setup DockerHub automated build
  2. Push code changes to github
  3. DockerHub sees changes and pulls/builds the image
  4. DockerHub calls webhooks for image

The payload DockerHub sends to webhook services is a POST request with some JSON about the image

      "description":"my docker repo that does cool things",
      "full_description":"This is my full description",
      "dockerfile":"my full dockerfile is listed here",

This can already be integrated with Jenkins using the "DockerHub" plugin.

I have a demo Rails app here:

This is setup as an automated build with DockerHub:

It doesn't need to be an automated build for webhooks to work, but with an automated build I can push to GitHub and trigger the build to happen

In Jenkins I'm going to setup the trigger to do something on a successful build from DockerHub:

Screen Shot 2014-07-31 at 3.57.59 PM]

Then tell it to pull down my new image and run my tests by invoking docker run cpuguy83/docker-rails-dev-demo test:

Screen Shot 2014-07-31 at 4.00.33 PM

*You'll notice in my github repo the Dockerfile is using bin/start.rb to start this container, which itself maps the test argument to rake test

On DockerHub we need to setup the webhook. You can find the webhooks link on the main repo page, on the right-hand column under "Settings"

Screen Shot 2014-07-31 at 4.20.18 PM

Add the hook for our Jenkins instance:

Screen Shot 2014-07-31 at 4.02.25 PM

Change JENKINS to your Jenkins host. The path /dockerhub-webhook/ must stay as per the Jenkins plugin.

Away we go, full CI workflow with tests running in the actual real image, tied in with DockerHub as an automated build.

What's really aweomse is this works with your private repos as well!