Skip to content

Lightwieght Docker Hub webhook listener based on the Flask microframework for Python

License

Notifications You must be signed in to change notification settings

Praisebetoscience/dockerhub-webhook

Repository files navigation

dockerhub-webhook

PyPi version Travis CI Status Coveralls Coverage Code Climate Rating Requires.io Check

dockerhub-webhook listens to HTTP POST requests from dockerhub and triggers your scripts to update when a new container is available.

Features

  • Python 3.3+ support.
  • Pip installion availble
  • Lightweight - built using Flask.
  • Supports unlimited number of triggers.
  • Full logging support including script errors.

Installation (Option 1: from Git)

Dockerhub-webhook is supported on python 3.3, 3.4, 3.5, and 3.6. To install from the github repository, the first step is to clone it.

git clone https://github.com/Praisebetoscience/dockerhub-webhook.git

Then install dependencies.

pip install -r requirements.txt

Next we need to create the config file which contains our apikey, maps scripts to incoming repository hooks. We can start from the example config.py and filling in the variables listed.

cp config.py.example config.py

To generate an apikey you can use tools such as openssl or pwgen.

openssl rand -base64 30 | sed 's=/=\\/=g'
pwgen 30 1

Alternatively you can set the $DOCKERHOOK_TOKEN environment variable with your key. This will override anything in config.py.

The HOOKS dict in config.py maps respository names to serverside deploy scripts. Keys are the names of repositories (no namespace), and values are the full path to the script to be called, or a relative path to the current working directory.

HOOKS = {'repo1': '/full/path/to/script.sh',
         'repo2': 'relative_path_to_script.sh'
        }

WSGI server (ex Gunicorn)

It is highly recommened you install a production ready WSGI server and not use the server packaged with Flask (Werkzeug) because it’s geared towards development. Here’s a quick example of how to start the application with Gunicorn. Gunicorn is typically reversed proxied by nginx.

NOTE: dockerhub-webhook looks for config.py in the current working directory.

pip install gunicorn
gunicorn dockerhook:app -w 1 -b <host_ip>:<port>

Installation (Option 2: pip)

The biggest devation from installing from github is the directory stucture where the config file, logs, and optionally scripts needs to be created

mkdir -p dockerhook/log
mkdir -p dockerhook/scripts

You create your config file just as above, but instead of coming with the source, you have to download the example directly.

cd dockerhook
wget -o config.py https://raw.githubusercontent.com/Praisebetoscience/dockerhub-webhook/master/config.py.example

Install using pip

pip install dockerhub-webhook

Configure Docker Hub

  1. Go to https://hub.docker.com
  2. Click the repository you wish to autodeploy
  3. Under the Webhooks tab add a webhook
  4. Choose any name you please
  5. For the Webhook URL use the following:
http://example.com/hubhook?key=secret

Adjust the domain and endpoint to your reverse proxy setting, and replace secret with your API key.

License

dockerhub-webhook source code is provided under the Apachi 2.0 License.

  • Copyright (c), 2017, PrasieBeToScience.

Development

Webhook uses github-flow for managing branches and follows PEP8 as much as possible.

To start Flask's development Werkzeug server you can use run.py.

You can run pytest unittests using python setup.py test.

About

Lightwieght Docker Hub webhook listener based on the Flask microframework for Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published