From cd1b003ca65180324e4e16b7e982eac99544f6a6 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Mon, 23 Mar 2015 15:37:30 -0400 Subject: [PATCH] buildcomponent: handle builds without resource_key --- buildman/component/buildcomponent.py | 6 ++++-- endpoints/api/build.py | 2 +- endpoints/api/trigger.py | 2 +- endpoints/trigger.py | 16 ++++++++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/buildman/component/buildcomponent.py b/buildman/component/buildcomponent.py index 002c87602..ec0710e0c 100644 --- a/buildman/component/buildcomponent.py +++ b/buildman/component/buildcomponent.py @@ -93,8 +93,10 @@ class BuildComponent(BaseComponent): self._build_failure('Could not load build job information', irbe) base_image_information = {} - buildpack_url = self.user_files.get_file_url(build_job.repo_build.resource_key, - requires_cors=False) + buildpack_url = "" + if build_job.repo_build.resource_key is not None: + buildpack_url = self.user_files.get_file_url(build_job.repo_build.resource_key, + requires_cors=False) # Add the pull robot information, if any. if build_job.pull_credentials: diff --git a/endpoints/api/build.py b/endpoints/api/build.py index 2add3adc4..8c3c2c8f0 100644 --- a/endpoints/api/build.py +++ b/endpoints/api/build.py @@ -101,7 +101,7 @@ def build_status_view(build_obj, can_write=False): } } - if can_write: + if can_write and build_obj.resource_key is not None: resp['archive_url'] = user_files.get_file_url(build_obj.resource_key, requires_cors=True) return resp diff --git a/endpoints/api/trigger.py b/endpoints/api/trigger.py index 8436d03db..1d1209c17 100644 --- a/endpoints/api/trigger.py +++ b/endpoints/api/trigger.py @@ -418,7 +418,7 @@ class ActivateBuildTrigger(RepositoryParamResource): try: run_parameters = request.get_json() - specs = handler.manual_start(trigger.auth_token, config_dict, run_parameters=run_parameters) + specs = handler.manual_start(trigger, run_parameters=run_parameters) dockerfile_id, tags, name, subdir, metadata = specs repo = model.get_repository(namespace, repository) diff --git a/endpoints/trigger.py b/endpoints/trigger.py index 20fea2cde..f621cacb4 100644 --- a/endpoints/trigger.py +++ b/endpoints/trigger.py @@ -4,13 +4,13 @@ import os.path import tarfile import base64 import re +import json from github import Github, UnknownObjectException, GithubException from tempfile import SpooledTemporaryFile from app import app, userfiles as user_files, github_trigger from util.tarfileappender import TarfileAppender -from endpoints.api.build import get_trigger_config client = app.config['HTTPCLIENT'] @@ -147,6 +147,12 @@ class BuildTrigger(object): def raise_unsupported(): raise io.UnsupportedOperation +def get_trigger_config(trigger): + try: + return json.loads(trigger.config) + except: + return {} + class GithubBuildTrigger(BuildTrigger): """ @@ -405,6 +411,9 @@ class GithubBuildTrigger(BuildTrigger): dockerfile_id = user_files.store_file(appender, TARBALL_MIME) logger.debug('Successfully prepared job') + else: + dockerfile_id = None + # compute the tag(s) branch = ref.split('/')[-1] @@ -417,7 +426,10 @@ class GithubBuildTrigger(BuildTrigger): # compute the subdir repo_subdir = config['subdir'] - joined_subdir = os.path.join(tarball_subdir, repo_subdir) + if trigger.private_key is None: + joined_subdir = os.path.join(tarball_subdir, repo_subdir) + else: + joined_subdir = repo_subdir logger.debug('Final subdir: %s', joined_subdir) # compute the metadata