Skip to content

Latest commit

 

History

History
91 lines (50 loc) · 4.82 KB

README.md

File metadata and controls

91 lines (50 loc) · 4.82 KB

dockerhub2ci

Build Status Test Coverage Code Climate

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:

  1. Push to Github
  2. Automated build runs on Dockerhub
  3. Webhook is sent to dockerhub2ci if Docker image is successfully built
  4. dockerhub2ci triggers a build on your CI
  5. CI runs the build and deploys using the latest image

Deploy to dockerhub2ci to Heroku

Deploy

Configuration

See app.json for list of the main configuration options.

Optional configuration options are listed below:

DISABLE_TAG_PASSTHROUGH

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

REPO_MAPPINGS

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.

TAG_MAPPINGS

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

TRAVIS_ENDPOINT

Set to https://api.travis-ci.com for private repositories.

Defaults to https://api.travis-ci.org

TRAVIS_CONTENT_TYPE

The content type header for Travis API requests.

Defaults to application/json

TRAVIS_API_VERSION

The API version header for Travis API requests.

Defaults to 3

Setup your Webhook on Dockerhub

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

Dockerhub Webhook Settings

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.

Travis Repo Settings

Contributing

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).

License

The software is available as open source under the terms of the MIT License.