Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ from the github repository, the first step is to clone it.

.. code-block:: bash

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

Then install dependencies.

Expand All @@ -70,14 +70,15 @@ Alternatively you can set the ``$DOCKERHOOK_TOKEN`` environment variable with yo
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.
scripts. Keys are the names of repositories (no namespace), and value is a dict data type,
and the ``default`` means that if not matched a tag. Each tag maps a full path to the script to be called,
or a relative path to the current working directory.

.. code-block:: python

HOOKS = {'repo1': '/full/path/to/script.sh',
'repo2': 'relative_path_to_script.sh'
HOOKS = {
'repo1': {'default':'tests_script2.sh','latest':'test_tags_script_latest.sh'},
'repo2': {'default':'tests_script.sh','2.0':'test_tags_script.sh'}
}


Expand Down
5 changes: 4 additions & 1 deletion config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
APIKEY = 'secret'

# Add your script using the name of your repository as the key
HOOKS = {'testpush': 'scripts/test.sh'}
HOOKS = {
'repo1': {'default':'tests_script2.sh','latest':'test_tags_script_latest.sh'},
'repo2': {'default':'tests_script.sh','2.0':'test_tags_script.sh'}
}
15 changes: 10 additions & 5 deletions dockerhook/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ def run_script(cls, json_data):
Returns:
Dict: JSON Response
"""
hook = json_data['repository']['name']
script_args = shlex.split(app.config['HOOKS'][hook])
app.logger.info("Subprocess [%s]: %s", hook, script_args)
repname = json_data['repository']['name']
tagname = json_data['push_data']['tag']
repsDic = app.config['HOOKS'][repname]
hk_tag_name = tagname
if tagname not in repsDic:
hk_tag_name = 'default'
script_args = shlex.split(app.config['HOOKS'][repname][hk_tag_name])
app.logger.info("Subprocess [%s (tag: %s)]: %s", repname,hk_tag_name, script_args)

try:
script_process = subprocess.Popen(
Expand All @@ -107,11 +112,11 @@ def run_script(cls, json_data):
app.logger.error('Exception occured: %s', str(exception))
app.logger.info('Subprocess failed.')
res = cls.create_response(
'error', '500', '{} failed.'.format(hook))
'error', '500', '{} {} failed.'.format(repname,hk_tag_name))
else:
# no exception raised.
res = cls.create_response(
'success', '200', '{} deployed.'.format(hook))
'success', '200', '{} {} deployed.'.format(repname,hk_tag_name))
app.logger.info('Script completed successfully.')

cls.callback(res, json_data['callback_url'])
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests==2.14.2
Flask==0.12.2
requests
Flask