WIP: Get everything working except logging and job completion
This commit is contained in:
parent
eacf3f01d2
commit
f93c0a46e8
6 changed files with 120 additions and 52 deletions
|
@ -3,8 +3,10 @@ import logging
|
|||
import json
|
||||
import trollius
|
||||
|
||||
from autobahn.wamp.exception import ApplicationError
|
||||
from trollius.coroutines import From
|
||||
from buildman.basecomponent import BaseComponent
|
||||
from buildman.buildpack import BuildPackage, BuildPackageException
|
||||
|
||||
HEARTBEAT_DELTA = datetime.timedelta(seconds=15)
|
||||
|
||||
|
@ -41,28 +43,21 @@ class BuildComponent(BaseComponent):
|
|||
def is_ready(self):
|
||||
return self.current_phase == 'running'
|
||||
|
||||
def start_build(self, job_item):
|
||||
def start_build(self, build_job):
|
||||
if not self.is_ready():
|
||||
return False
|
||||
|
||||
self.job_item = job_item
|
||||
self.current_job = build_job
|
||||
self._set_phase('building')
|
||||
|
||||
# Parse the build job's config.
|
||||
logger.debug('Parsing job JSON configuration block')
|
||||
try:
|
||||
job_config = json.loads(job_item.body)
|
||||
except ValueError:
|
||||
self._build_failure('Could not parse build job configuration')
|
||||
return False
|
||||
|
||||
# Retrieve the job's buildpack.
|
||||
buildpack_url = self.user_files.get_file_url(job_item.resource_key, requires_cors=False)
|
||||
logger.debug('Retreiving build package: %s' % buildpack_url)
|
||||
buildpack_url = self.user_files.get_file_url(build_job.repo_build().resource_key,
|
||||
requires_cors=False)
|
||||
|
||||
logger.debug('Retreiving build package: %s' % buildpack_url)
|
||||
buildpack = None
|
||||
try:
|
||||
buildpack = BuildPack.from_url(buildpack_url)
|
||||
buildpack = BuildPackage.from_url(buildpack_url)
|
||||
except BuildPackageException as bpe:
|
||||
self._build_failure('Could not retrieve build package', bpe)
|
||||
return False
|
||||
|
@ -71,8 +66,9 @@ class BuildComponent(BaseComponent):
|
|||
parsed_dockerfile = None
|
||||
logger.debug('Parsing dockerfile')
|
||||
|
||||
build_config = build_job.build_config()
|
||||
try:
|
||||
parsed_dockerfile = buildpack.parse_dockerfile(job_config.get('build_subdir'))
|
||||
parsed_dockerfile = buildpack.parse_dockerfile(build_config.get('build_subdir'))
|
||||
except BuildPackageException as bpe:
|
||||
self._build_failure('Could not find Dockerfile in build package', bpe)
|
||||
return False
|
||||
|
@ -88,12 +84,12 @@ class BuildComponent(BaseComponent):
|
|||
}
|
||||
|
||||
# Add the pull robot information, if any.
|
||||
if job_config.get('pull_credentials') is not None:
|
||||
base_image_information['username'] = job_config['pull_credentials'].get('username', '')
|
||||
base_image_information['password'] = job_config['pull_credentials'].get('password', '')
|
||||
if build_config.get('pull_credentials') is not None:
|
||||
base_image_information['username'] = build_config['pull_credentials'].get('username', '')
|
||||
base_image_information['password'] = build_config['pull_credentials'].get('password', '')
|
||||
|
||||
# Retrieve the repository's full name.
|
||||
repo = job_config.repository
|
||||
repo = build_job.repo_build().repository
|
||||
repository_name = repo.namespace_user.username + '/' + repo.name
|
||||
|
||||
# Parse the build queue item into build arguments.
|
||||
|
@ -111,17 +107,18 @@ class BuildComponent(BaseComponent):
|
|||
# password: The password for pulling the base image (if any).
|
||||
build_arguments = {
|
||||
'build_package': buildpack_url,
|
||||
'sub_directory': job_config.get('build_subdir', ''),
|
||||
'sub_directory': build_config.get('build_subdir', ''),
|
||||
'repository': repository_name,
|
||||
'registry': self.server_hostname,
|
||||
'pull_token': job_item.access_token.code,
|
||||
'push_token': job_item.access_token.code,
|
||||
'tag_names': job_config.get('docker_tags', ['latest']),
|
||||
'base_image': base_image_information
|
||||
'pull_token': build_job.repo_build().access_token.code,
|
||||
'push_token': build_job.repo_build().access_token.code,
|
||||
'tag_names': build_config.get('docker_tags', ['latest']),
|
||||
'base_image': base_image_information,
|
||||
'cached_tag': build_job.determine_cached_tag() or ''
|
||||
}
|
||||
|
||||
# Invoke the build.
|
||||
logger.debug('Invoking build: %s', token)
|
||||
# Invoke the build.
|
||||
logger.debug('Invoking build: %s', self.builder_realm)
|
||||
logger.debug('With Arguments: %s', build_arguments)
|
||||
|
||||
(self.call("io.quay.builder.build", **build_arguments)
|
||||
|
@ -131,7 +128,8 @@ class BuildComponent(BaseComponent):
|
|||
|
||||
def _build_failure(self, error_message, exception=None):
|
||||
# TODO: log this message
|
||||
print error_kind
|
||||
print error_message
|
||||
print exception
|
||||
self._set_phase('running')
|
||||
|
||||
def _build_complete(self, result):
|
||||
|
@ -204,9 +202,9 @@ class BuildComponent(BaseComponent):
|
|||
def _dispose(self, timed_out=False):
|
||||
# If we still have a running job, then it has not completed and we need to tell the parent
|
||||
# manager.
|
||||
if self.job_item is not None:
|
||||
self.parent_manager.job_completed(job_item, 'incomplete', self)
|
||||
self.job_item = None
|
||||
if self.current_job is not None:
|
||||
self.parent_manager.job_completed(self.current_job, 'incomplete', self)
|
||||
self.current_job = None
|
||||
|
||||
# Unregister the current component so that it cannot be invoked again.
|
||||
self.parent_manager.build_component_disposed(self, timed_out)
|
||||
|
|
Reference in a new issue