diff --git a/endpoints/api/tag.py b/endpoints/api/tag.py index 9e928df93..d3c6352c7 100644 --- a/endpoints/api/tag.py +++ b/endpoints/api/tag.py @@ -230,12 +230,8 @@ class RestoreTag(RepositoryParamResource): # Restore the tag back to the previous image. image_id = request.get_json()['image'] manifest_digest = request.get_json().get('manifest_digest', None) - if manifest_digest is not None: - existing_image = model.tag.restore_tag_to_manifest(repo, tag, manifest_digest) - else: - existing_image = model.tag.restore_tag_to_image(repo, tag, image_id) - # Log the reversion/restoration. + # Data for logging the reversion/restoration. username = get_authenticated_user().username log_data = { 'username': username, @@ -244,6 +240,17 @@ class RestoreTag(RepositoryParamResource): 'image': image_id, } + if manifest_digest is not None: + existing_image = model.tag.restore_tag_to_manifest(repo, tag, manifest_digest) + else: + existing_image = model.tag.restore_tag_to_image(repo, tag, image_id) + try: + _generate_and_store_manifest(namespace, repository, tag) + except: + # log and move on since we'll attempt to store manifest on first pull as well + logger.exception('unable to store manifest for tag', extra=log_data) + + if existing_image is not None: log_data['original_image'] = existing_image.docker_image_id