diff options
| -rw-r--r-- | triggers.py | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/triggers.py b/triggers.py index 83a7b21..cf141a1 100644 --- a/triggers.py +++ b/triggers.py @@ -11,44 +11,29 @@ class test(object): class varnishpurger(object): """ - Push trigger that purges repositories from varnish. The idea being that - the repositories follow a standard gitweb url structure, and we purge - all pages related to that repository. + Push trigger that purges repositories from varnish. Each repository is + expected to be tagged with an xkey of repo_<reponame>. All index pages + are expected to be tagged with the xkey repoindex. Requires the config variable "host" set in the section "varnishpurge". This can be an IP address (typically 127.0.0.1) or IP address + port (typically 127.0.0.1:81). The trigger will always post to the URL - "/varnish-purge-url", and will include the URL to purge in the form of - a regular expression in the custom header X-Purge-URL. + "/varnish-purge-xkey", and will include the xkeys to purge in the + header xkey. """ def __init__(self, cfg): self.host = cfg.get('varnishpurge', 'host') def pushtrigger(self, reponame, username): # Make a callback to a local varnish server to purge a repository - # from it, both gitweb and cgit. - # Also, purge the actual http serving git repo itself. - for u in [ - r'^/gitweb/?$', - r'^/gitweb/\?p=%s.git' % reponame, - r'^/git/%s' % reponame, - r'^/cgit/?$', - r'^/cgit/%s.git' % reponame, - ]: - if not self._internal_purge(u): - print("Varnish purge failed, website may become slightly out of date") - return - - def _internal_purge(self, url): + # from it. try: resp = requests.get( - "http://{0}/varnish-purge-url".format(self.host), + "http://{0}/varnish-purge-xkey".format(self.host), headers={ - 'X-Purge-URL': url, + 'xkey': 'repoindex repo_{}'.format(reponame), } ) - if resp.status_code == 200: - return True - return False + resp.raise_for_status() except Exception as ex: - return False + print("Varnish purge failed, website may become slightly out of date") |
