Skip to main content

Webhook handler for dockerhub autodeployments

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dockerhub-webhook-0.2.1.tar.gz (6.8 kB view hashes)

Uploaded Source

Built Distribution

dockerhub_webhook-0.2.1-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page