dockerhub2ci handles Dockerhub's Webhooks so you can trigger CI on a successful build. It has built in support for Travis.
Example Use Case
Some of my applications run on AWS Elastic Beanstalk (multi-container docker). It's relatively straight forward to setup automated deployment to Elastic Beanstalk via Travis, however when a deployment is triggered on Elastic Beanstalk it pulls the latest image from Dockerhub. Most of the time the travis build completes and deployment is triggered before Dockerhub has successfully built the new image so the old image is redeployed to Elastic Beanstalk.
Using dockerhub2ci you can setup the following workflow:
- Push to Github
- Automated build runs on Dockerhub
- Webhook is sent to dockerhub2ci if Docker image is successfully built
- dockerhub2ci triggers a build on your CI
- CI runs the build and deploys using the latest image
Deploy to dockerhub2ci to Heroku
See app.json for list of the main configuration options.
Optional configuration options are listed below:
One or more Dockerhub repo to build repo name mappings (separated by semicolons (;)). For example if you want the Dockerhub repository
dwilkie-docker/dockerhub2ci to trigger a build on
REPO_MAPPINGS=dwilkie-docker/dockerhub2ci=dwilkie/dockerhub2ci. If there is no mapping for the Dockerhub repo, it's assumed the build repo is the same as the Dockerhub repo.
One or more Dockerhub tag to build branch name mappings (separated by semicolons (;)). For example if you want the
lastest Dockerhub tag to trigger a build on the
staging branch and the
stable Dockerhub tag to trigger a build on the master branch set
TAG_MAPPINGS=latest=staging;stable=master. If there is no mapping for the Dockerhub tag, it's assumed the build branch name is the same as the Dockerhub tag name.
https://api.travis-ci.com for private repositories.
The content type header for Travis API requests.
The API version header for Travis API requests.
Setup your Webhook on Dockerhub
Set the Webhook URL in your Dockerhub configuration
api-key with one of the keys you set in
API_KEYS and replace
your-dockerhub2ci-app.herokuapp.com with the domain of your dockerhub2ci instance. Don't forget the trailing colon (:) after the
Turn off automated builds on your CI
After you have setup dockerhub2ci to trigger builds you can turn off automated builds on your CI. Here's a screenshot of how to turn off automated builds on Travis.
dockerhub2ci use the publish-subscribe pattern so that additional subscribers can be added with ease. Subscribers are configured using the
WEBHOOK_SUBSCRIBERS environment variable (see app.json for more info).
A subscriber just needs to implement the
perform! method which takes one argument which is the payload from the Dockerhub webhook (see WebhookSubscriber::Travis for an example).
The software is available as open source under the terms of the MIT License.