Prepare the build worker to support multiple tags and subdirectories. Change the build database config to accept a job config object instead of breaking out the parameters into independent blocks.
This commit is contained in:
parent
4b0f4c0a7b
commit
13dea98499
9 changed files with 114 additions and 53 deletions
|
@ -55,7 +55,8 @@ class BuildTrigger(object):
|
|||
|
||||
def handle_trigger_request(self, request, auth_token, config):
|
||||
"""
|
||||
Transform the incoming request data into a set of actions.
|
||||
Transform the incoming request data into a set of actions. Returns a tuple
|
||||
of usefiles resource id, docker tags, build name, and resource subdir.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -163,7 +164,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
try:
|
||||
repo = gh_client.get_repo(source)
|
||||
default_commit = repo.get_branch(repo.default_branch).commit
|
||||
default_commit = repo.get_branch(repo.master_branch).commit
|
||||
commit_tree = repo.get_git_tree(default_commit.sha, recursive=True)
|
||||
|
||||
return [os.path.dirname(elem.path) for elem in commit_tree.tree
|
||||
|
@ -181,7 +182,8 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
logger.debug('Payload %s', payload)
|
||||
ref = payload['ref']
|
||||
commit_id = payload['head_commit']['id'][0:7]
|
||||
commit_sha = payload['head_commit']['id']
|
||||
short_sha = commit_sha[0:7]
|
||||
|
||||
gh_client = self._get_client(auth_token)
|
||||
|
||||
|
@ -192,8 +194,7 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
logger.debug('Github repo: %s', repo)
|
||||
|
||||
# Prepare the download and upload URLs
|
||||
branch_name = ref.split('/')[-1]
|
||||
archive_link = repo.get_archive_link('zipball', branch_name)
|
||||
archive_link = repo.get_archive_link('zipball', short_sha)
|
||||
download_archive = client.get(archive_link, stream=True)
|
||||
|
||||
with SpooledTemporaryFile(CHUNK_SIZE) as zipball:
|
||||
|
@ -204,4 +205,17 @@ class GithubBuildTrigger(BuildTrigger):
|
|||
|
||||
logger.debug('Successfully prepared job')
|
||||
|
||||
return dockerfile_id, branch_name, commit_id
|
||||
# compute the tag(s)
|
||||
pushed_branch = ref.split('/')[-1]
|
||||
tags = {pushed_branch}
|
||||
if pushed_branch == repo.master_branch:
|
||||
tags.add('latest')
|
||||
logger.debug('Pushing to tags: %s' % tags)
|
||||
|
||||
# compute the subdir
|
||||
repo_subdir = config['subdir']
|
||||
zipball_subdir = '%s-%s-%s' % (repo.owner.login, repo.name, short_sha)
|
||||
joined_subdir = os.path.join(zipball_subdir, repo_subdir)
|
||||
logger.debug('Final subdir: %s' % joined_subdir)
|
||||
|
||||
return dockerfile_id, list(tags), short_sha, joined_subdir
|
||||
|
|
Reference in a new issue