Webhook handler for dockerhub autodeployments
Project description
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
Go to https://hub.docker.com
Click the repository you wish to autodeploy
Under the Webhooks tab add a webhook
Choose any name you please
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dockerhub_webhook-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7627a4cc3d0f40274c26bdb7bfd5147117598bdbd851acbb0dff4b395ff60fa3 |
|
MD5 | 328e48988f4190c6f3f86d2c2cd6a229 |
|
BLAKE2b-256 | 7fe9fd3fb6b453b7a3819ba36b903b4390bbefab603f5b17b4ee08c84c415ba5 |