Move manifest backfill for V1 tags into the new registry model interface

This commit is contained in:
Joseph Schorr 2018-08-27 15:01:27 -04:00
parent 95b7850c20
commit f297249100
8 changed files with 157 additions and 45 deletions

View file

@ -10,7 +10,6 @@ from endpoints.api import (resource, nickname, require_repo_read, require_repo_w
parse_args, query_param, truthy_bool, disallow_for_app_repositories)
from endpoints.api.image import image_dict
from endpoints.exception import NotFound, InvalidRequest
from endpoints.v2.manifest import _generate_and_store_manifest
from util.names import TAG_ERROR, TAG_REGEX
@ -155,9 +154,6 @@ class RepositoryTag(RepositoryParamResource):
'original_image': existing_tag.legacy_image.docker_image_id if existing_tag else None,
}, repo_name=repository)
# TODO(jschorr): Move this into the retarget_tag call
_generate_and_store_manifest(namespace, repository, tag)
return 'Updated', 201
@require_repo_write
@ -279,10 +275,6 @@ class RestoreTag(RepositoryParamResource):
if not registry_model.retarget_tag(repo_ref, tag, manifest_or_legacy_image, is_reversion=True):
raise InvalidRequest('Could not restore tag')
if manifest_digest is None:
# TODO(jschorr): Move this into the retarget_tag call
_generate_and_store_manifest(namespace, repository, tag)
log_action('revert_tag', namespace, log_data, repo_name=repository)
return {

View file

@ -9,6 +9,7 @@ import features
from app import docker_v2_signing_key, app, metric_queue
from auth.registry_jwt_auth import process_registry_jwt_auth
from digest import digest_tools
from data.registry_model import registry_model
from endpoints.decorators import anon_protect, parse_repository_name
from endpoints.v2 import v2_bp, require_repo_read, require_repo_write
from endpoints.v2.models_interface import Label
@ -52,7 +53,18 @@ def fetch_manifest_by_tagname(namespace_name, repo_name, manifest_ref):
else:
raise ManifestUnknown()
manifest = _generate_and_store_manifest(namespace_name, repo_name, manifest_ref)
repo_ref = registry_model.lookup_repository(namespace_name, repo_name)
if repo_ref is None:
raise ManifestUnknown()
tag = registry_model.get_repo_tag(repo_ref, manifest_ref, include_legacy_image=True)
if tag is None:
raise ManifestUnknown()
if not registry_model.backfill_manifest_for_tag(tag):
raise ManifestUnknown()
manifest = model.get_manifest_by_tag(namespace_name, repo_name, manifest_ref)
if manifest is None:
raise ManifestUnknown()
@ -259,35 +271,3 @@ def delete_manifest_by_digest(namespace_name, repo_name, manifest_ref):
track_and_log('delete_tag', tag.repository, tag=tag.name, digest=manifest_ref)
return Response(status=202)
def _generate_and_store_manifest(namespace_name, repo_name, tag_name):
""" Generates and stores a manifest for an existing V1-only tag. """
# TODO(jschorr): Remove once we are fully on Manifest-based model.
# Find the v1 metadata for this image and its parents.
v1_metadata = model.get_docker_v1_metadata_by_tag(namespace_name, repo_name, tag_name)
parents_v1_metadata = model.get_parents_docker_v1_metadata(namespace_name, repo_name,
v1_metadata.image_id)
# If the manifest is being generated under the library namespace, then we make its namespace
# empty.
manifest_namespace = namespace_name
if features.LIBRARY_SUPPORT and namespace_name == app.config['LIBRARY_NAMESPACE']:
manifest_namespace = ''
# Create and populate the manifest builder
builder = DockerSchema1ManifestBuilder(manifest_namespace, repo_name, tag_name)
# Add the leaf layer
builder.add_layer(v1_metadata.content_checksum, v1_metadata.compat_json)
for parent_v1_metadata in parents_v1_metadata:
builder.add_layer(parent_v1_metadata.content_checksum, parent_v1_metadata.compat_json)
# Sign the manifest with our signing key.
manifest = builder.build(docker_v2_signing_key)
# Write the manifest to the DB.
model.create_manifest_and_update_tag(namespace_name, repo_name, tag_name, manifest)
return manifest