Properly connect the github push webhook with the build worker. Still need to resolve the archive format.
This commit is contained in:
parent
ed38bcdafc
commit
f60f9eb62a
8 changed files with 57 additions and 34 deletions
|
@ -1,19 +1,21 @@
|
|||
import json
|
||||
import requests
|
||||
import logging
|
||||
import io
|
||||
|
||||
from github import Github
|
||||
from tempfile import SpooledTemporaryFile
|
||||
|
||||
from app import app
|
||||
|
||||
|
||||
user_files = app.config['USERFILES']
|
||||
client = app.config['HTTPCLIENT']
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
ZIPBALL = 'application/zip'
|
||||
CHUNK_SIZE = 512 * 1024
|
||||
|
||||
|
||||
class BuildArchiveException(Exception):
|
||||
|
@ -35,7 +37,7 @@ class BuildTrigger(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def incoming_webhook(self, request, auth_token, config):
|
||||
def handle_trigger_request(self, request, auth_token, config):
|
||||
"""
|
||||
Transform the incoming request data into a set of actions.
|
||||
"""
|
||||
|
@ -57,6 +59,10 @@ class BuildTrigger(object):
|
|||
raise InvalidServiceException('Unable to find service: %s' % service)
|
||||
|
||||
|
||||
def raise_unsupported():
|
||||
raise io.UnsupportedOperation
|
||||
|
||||
|
||||
class GithubBuildTrigger(BuildTrigger):
|
||||
@staticmethod
|
||||
def _get_client(auth_token):
|
||||
|
@ -77,7 +83,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
return repo_list
|
||||
|
||||
def incoming_webhook(self, request, auth_token, config):
|
||||
def handle_trigger_request(self, request, auth_token, config):
|
||||
payload = request.get_json()
|
||||
logger.debug('Payload %s', payload)
|
||||
ref = payload['ref']
|
||||
|
@ -94,17 +100,13 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
# Prepare the download and upload URLs
|
||||
branch_name = ref.split('/')[-1]
|
||||
archive_link = repo.get_archive_link('zipball', branch_name)
|
||||
download_archive = requests.get(archive_link, stream=True)
|
||||
download_archive = client.get(archive_link, stream=True)
|
||||
|
||||
upload_url, dockerfile_id = user_files.prepare_for_drop(ZIPBALL)
|
||||
up_headers = {'Content-Type': ZIPBALL}
|
||||
upload_archive = requests.put(upload_url, headers=up_headers,
|
||||
data=download_archive.raw)
|
||||
with SpooledTemporaryFile(CHUNK_SIZE) as zipball:
|
||||
for chunk in download_archive.iter_content(CHUNK_SIZE):
|
||||
zipball.write(chunk)
|
||||
|
||||
if upload_archive.status_code / 100 != 2:
|
||||
logger.debug('Failed to upload archive to s3')
|
||||
raise BuildArchiveException('Unable to copy archie to s3 for ref: %s' %
|
||||
ref)
|
||||
dockerfile_id = user_files.store_file(zipball, ZIPBALL)
|
||||
|
||||
logger.debug('Successfully prepared job')
|
||||
|
||||
|
|
Reference in a new issue