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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file dockerhub-webhook-0.2.1.tar.gz.

File metadata

File hashes

Hashes for dockerhub-webhook-0.2.1.tar.gz
Algorithm Hash digest
SHA256 76d7f0e886e7fd22a593b3955e8bcd50d06ecebd8a83b3ea2bfb4afedf5c01d0
MD5 8fbd110d9977e5fd6e50ad31007741d4
BLAKE2b-256 3c0a517489db4182a961c996ac31223f029e9276fd11328e247121a8d955aaf9

See more details on using hashes here.

File details

Details for the file dockerhub_webhook-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dockerhub_webhook-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7627a4cc3d0f40274c26bdb7bfd5147117598bdbd851acbb0dff4b395ff60fa3
MD5 328e48988f4190c6f3f86d2c2cd6a229
BLAKE2b-256 7fe9fd3fb6b453b7a3819ba36b903b4390bbefab603f5b17b4ee08c84c415ba5

See more details on using hashes here.

Supported by

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