dockerhub2ci handles Dockerhub's Webhooks so you can trigger CI on a successful build. It has built in support for Travis.
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
See app.json for list of the main configuration options.
Optional configuration options are listed below:
By default all Dockerhub tags will be used to trigger builds using the same branch name, unless name remapping is defined with TAG_MAPPINGS
. Should you want to only rely on TAG_MAPPINGS
and prevent any unknown Dockerhub tags from triggering build, set this to 1
.
Defaults to 0
One or more Dockerhub repo to build repo name mappings (separated by semicolons (;)). For example if you want the Dockerhub repository somleng-docker/dockerhub2ci
to trigger a build on somleng/dockerhub2ci
set REPO_MAPPINGS=somleng-docker/dockerhub2ci=somleng/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. However if a mapping for the Dockerhub tag does exist but is empty, then it will be skipped: no builds for this tag will be triggered.
Defaults to latest=master
Set to https://api.travis-ci.com
for private repositories.
Defaults to https://api.travis-ci.org
The content type header for Travis API requests.
Defaults to application/json
The API version header for Travis API requests.
Defaults to 3
Set the Webhook URL in your Dockerhub configuration
https://api-key:@your-dockerhub2ci-app.herokuapp.com/api/webhooks
Replace 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 api-key
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.