port label support to refactored v2 registry

This commit is contained in:
Jimmy Zelinskie 2016-09-20 22:09:25 -04:00
parent 3c8b87e086
commit ca883e5662
5 changed files with 66 additions and 11 deletions

View file

@ -4,7 +4,7 @@ from namedlist import namedlist
from peewee import IntegrityError
from data import model, database
from data.model import DataModelException
from data.model import DataModelException, TagAlreadyCreatedException
from image.docker.v1 import DockerV1Metadata
_MEDIA_TYPE = "application/vnd.docker.distribution.manifest.v1+prettyjws"
@ -48,6 +48,11 @@ class RepositoryReference(namedtuple('RepositoryReference', ['id', 'name', 'name
RepositoryReference represents a reference to a Repository, without its full metadata.
"""
class Label(namedtuple('Label', ['key', 'value', 'source_type', 'media_type'])):
"""
Label represents a key-value pair that describes a particular Manifest.
"""
class DockerRegistryV2DataInterface(object):
"""
@ -158,6 +163,8 @@ class DockerRegistryV2DataInterface(object):
"""
Saves a manifest pointing to the given leaf image, with the given manifest, under the matching
repository as a tag with the given name.
Returns a boolean whether or not the tag was newly created or not.
"""
raise NotImplementedError()
@ -246,6 +253,14 @@ class DockerRegistryV2DataInterface(object):
"""
raise NotImplementedError()
@classmethod
def create_manifest_labels(cls, namespace_name, repo_name, manifest_digest, labels):
"""
Creates a new labels for the provided manifest.
"""
raise NotImplementedError()
@classmethod
def get_blob_path(cls, blob):
"""
@ -407,8 +422,10 @@ class PreOCIModel(DockerRegistryV2DataInterface):
@classmethod
def save_manifest(cls, namespace_name, repo_name, tag_name, leaf_layer_docker_id, manifest_digest,
manifest_bytes):
model.tag.store_tag_manifest(namespace_name, repo_name, tag_name, leaf_layer_docker_id,
manifest_digest, manifest_bytes)
(_, newly_created) = model.tag.store_tag_manifest(namespace_name, repo_name, tag_name,
leaf_layer_docker_id, manifest_digest,
manifest_bytes)
return newly_created
@classmethod
def repository_tags(cls, namespace_name, repo_name, limit, offset):
@ -540,6 +557,17 @@ class PreOCIModel(DockerRegistryV2DataInterface):
blob_record = model.storage.get_storage_by_uuid(blob.uuid)
model.storage.save_torrent_info(blob_record, piece_size, piece_bytes)
@classmethod
def create_manifest_labels(cls, namespace_name, repo_name, manifest_digest, labels):
if not labels:
# No point in doing anything more.
return
tag_manifest = model.tag.load_manifest_by_digest(namespace_name, repo_name, manifest_digest)
for label in labels:
model.label.create_manifest_label(tag_manifest, label.key, label.value, label.source_type,
label.media_type)
@classmethod
def get_blob_path(cls, blob):
blob_record = model.storage.get_storage_by_uuid(blob.uuid)