Merge branch 'master' of ssh://bitbucket.org/yackob03/quay
This commit is contained in:
commit
00ac3fb639
4 changed files with 34 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
||||||
import redis
|
import redis
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
class BuildStatusRetrievalError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class BuildLogs(object):
|
class BuildLogs(object):
|
||||||
ERROR = 'error'
|
ERROR = 'error'
|
||||||
|
@ -45,7 +47,7 @@ class BuildLogs(object):
|
||||||
log_entries = self._redis.lrange(self._logs_key(build_id), start_index, -1)
|
log_entries = self._redis.lrange(self._logs_key(build_id), start_index, -1)
|
||||||
return (llen, (json.loads(entry) for entry in log_entries))
|
return (llen, (json.loads(entry) for entry in log_entries))
|
||||||
except redis.ConnectionError:
|
except redis.ConnectionError:
|
||||||
return (0, [])
|
raise BuildStatusRetrievalError('Cannot retrieve build logs')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _status_key(build_id):
|
def _status_key(build_id):
|
||||||
|
@ -65,6 +67,6 @@ class BuildLogs(object):
|
||||||
try:
|
try:
|
||||||
fetched = self._redis.get(self._status_key(build_id))
|
fetched = self._redis.get(self._status_key(build_id))
|
||||||
except redis.ConnectionError:
|
except redis.ConnectionError:
|
||||||
return None
|
raise BuildStatusRetrievalError('Cannot retrieve build status')
|
||||||
|
|
||||||
return json.loads(fetched) if fetched else None
|
return json.loads(fetched) if fetched else None
|
||||||
|
|
|
@ -11,6 +11,7 @@ from endpoints.common import start_build
|
||||||
from endpoints.trigger import BuildTrigger
|
from endpoints.trigger import BuildTrigger
|
||||||
from data import model
|
from data import model
|
||||||
from auth.permissions import ModifyRepositoryPermission
|
from auth.permissions import ModifyRepositoryPermission
|
||||||
|
from data.buildlogs import BuildStatusRetrievalError
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -48,11 +49,17 @@ def trigger_view(trigger):
|
||||||
|
|
||||||
|
|
||||||
def build_status_view(build_obj, can_write=False):
|
def build_status_view(build_obj, can_write=False):
|
||||||
status = build_logs.get_status(build_obj.uuid)
|
phase = build_obj.phase
|
||||||
|
try:
|
||||||
|
status = build_logs.get_status(build_obj.uuid)
|
||||||
|
except BuildStatusRetrievalError:
|
||||||
|
status = {}
|
||||||
|
phase = 'cannot_load'
|
||||||
|
|
||||||
logger.debug('Can write: %s job_config: %s', can_write, build_obj.job_config)
|
logger.debug('Can write: %s job_config: %s', can_write, build_obj.job_config)
|
||||||
resp = {
|
resp = {
|
||||||
'id': build_obj.uuid,
|
'id': build_obj.uuid,
|
||||||
'phase': build_obj.phase if status else 'cannot_load',
|
'phase': phase,
|
||||||
'started': format_date(build_obj.started),
|
'started': format_date(build_obj.started),
|
||||||
'display_name': build_obj.display_name,
|
'display_name': build_obj.display_name,
|
||||||
'status': status or {},
|
'status': status or {},
|
||||||
|
@ -169,7 +176,10 @@ class RepositoryBuildLogs(RepositoryParamResource):
|
||||||
|
|
||||||
start = int(request.args.get('start', 0))
|
start = int(request.args.get('start', 0))
|
||||||
|
|
||||||
count, logs = build_logs.get_log_entries(build.uuid, start)
|
try:
|
||||||
|
count, logs = build_logs.get_log_entries(build.uuid, start)
|
||||||
|
except BuildStatusRetrievalError:
|
||||||
|
count, logs = (0, [])
|
||||||
|
|
||||||
response_obj.update({
|
response_obj.update({
|
||||||
'start': start,
|
'start': start,
|
||||||
|
|
|
@ -13,7 +13,8 @@ from endpoints.api.build import (build_status_view, trigger_view, RepositoryBuil
|
||||||
get_trigger_config)
|
get_trigger_config)
|
||||||
from endpoints.common import start_build
|
from endpoints.common import start_build
|
||||||
from endpoints.trigger import (BuildTrigger as BuildTriggerBase, TriggerDeactivationException,
|
from endpoints.trigger import (BuildTrigger as BuildTriggerBase, TriggerDeactivationException,
|
||||||
TriggerActivationException, EmptyRepositoryException)
|
TriggerActivationException, EmptyRepositoryException,
|
||||||
|
RepositoryReadException)
|
||||||
from data import model
|
from data import model
|
||||||
from auth.permissions import UserAdminPermission
|
from auth.permissions import UserAdminPermission
|
||||||
|
|
||||||
|
@ -116,9 +117,14 @@ class BuildTriggerSubdirs(RepositoryParamResource):
|
||||||
'status': 'success'
|
'status': 'success'
|
||||||
}
|
}
|
||||||
except EmptyRepositoryException as exc:
|
except EmptyRepositoryException as exc:
|
||||||
|
return {
|
||||||
|
'status': 'success',
|
||||||
|
'subdir': []
|
||||||
|
}
|
||||||
|
except RepositoryReadException as exc:
|
||||||
return {
|
return {
|
||||||
'status': 'error',
|
'status': 'error',
|
||||||
'message': exc.msg
|
'message': exc.message
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
raise Unauthorized()
|
raise Unauthorized()
|
||||||
|
|
|
@ -38,6 +38,9 @@ class ValidationRequestException(Exception):
|
||||||
class EmptyRepositoryException(Exception):
|
class EmptyRepositoryException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class RepositoryReadException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BuildTrigger(object):
|
class BuildTrigger(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -209,9 +212,12 @@ class GithubBuildTrigger(BuildTrigger):
|
||||||
return [os.path.dirname(elem.path) for elem in commit_tree.tree
|
return [os.path.dirname(elem.path) for elem in commit_tree.tree
|
||||||
if (elem.type == u'blob' and
|
if (elem.type == u'blob' and
|
||||||
os.path.basename(elem.path) == u'Dockerfile')]
|
os.path.basename(elem.path) == u'Dockerfile')]
|
||||||
except GithubException:
|
except GithubException as ge:
|
||||||
msg = 'Unable to list contents of repository: %s' % source
|
message = ge.data.get('message', 'Unable to list contents of repository: %s' % source)
|
||||||
raise EmptyRepositoryException(msg)
|
if message == 'Branch not found':
|
||||||
|
raise EmptyRepositoryException()
|
||||||
|
|
||||||
|
raise RepositoryReadException(message)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _prepare_build(config, repo, commit_sha, build_name, ref):
|
def _prepare_build(config, repo, commit_sha, build_name, ref):
|
||||||
|
|
Reference in a new issue