Add labeling of built manifests with their build IDs

Also sends the digests to the notification

Fixes #593
This commit is contained in:
Joseph Schorr 2016-09-12 15:30:15 -04:00
parent 2b00c644b5
commit 02b8afe127
3 changed files with 27 additions and 3 deletions

View file

@ -14,6 +14,7 @@ from buildman.jobutil.buildjob import BuildJobLoadException
from buildman.jobutil.buildstatus import StatusHandler
from buildman.jobutil.workererror import WorkerError
from data import model
from data.database import BUILD_PHASE
HEARTBEAT_DELTA = datetime.timedelta(seconds=30)
@ -284,6 +285,8 @@ class BuildComponent(BaseComponent):
def _build_complete(self, result):
""" Wraps up a completed build. Handles any errors and calls self._build_finished. """
build_id = self._current_job.repo_build.uuid
try:
# Retrieve the result. This will raise an ApplicationError on any error that occurred.
result_value = result.result()
@ -300,10 +303,25 @@ class BuildComponent(BaseComponent):
self._build_status.set_phase(BUILD_PHASE.COMPLETE)
trollius.async(self._build_finished(BuildJobResult.COMPLETE))
# Label the pushed manifests with the build metadata.
manifest_digests = kwargs.get('digests') or []
for digest in manifest_digests:
try:
manifest = model.tag.load_manifest_by_digest(self._current_job.namespace,
self._current_job.repo_name, digest)
model.label.create_manifest_label(manifest, model.label.INTERNAL_LABEL_BUILD_UUID,
build_id, 'internal', 'text/plain')
except model.InvalidManifestException:
logger.debug('Could not find built manifest with digest %s under repo %s/%s for build %s',
digest, self._current_job.namespace, self._current_job.repo_name,
build_id)
continue
# Send the notification that the build has completed successfully.
self._current_job.send_notification('build_success', image_id=kwargs.get('image_id'))
self._current_job.send_notification('build_success',
image_id=kwargs.get('image_id'),
manifest_digests=manifest_digests)
except ApplicationError as aex:
build_id = self._current_job.repo_build.uuid
worker_error = WorkerError(aex.error, aex.kwargs.get('base_error'))
# Write the error to the log.