Move manifest backfill for V1 tags into the new registry model interface
This commit is contained in:
parent
95b7850c20
commit
f297249100
8 changed files with 157 additions and 45 deletions
|
@ -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
|
||||
|
|
Reference in a new issue