Basic labels support

Adds basic labels support to the registry code (V2), and the API. Note that this does not yet add any UI related support.
This commit is contained in:
Joseph Schorr 2016-07-18 18:20:00 -04:00
parent 427070b453
commit 608ffd9663
24 changed files with 907 additions and 36 deletions

View file

@ -10,7 +10,8 @@ from data.model import (DataModelException, tag, db_transaction, storage, permis
from data.database import (Repository, Namespace, RepositoryTag, Star, Image, User,
Visibility, RepositoryPermission, RepositoryActionCount,
Role, RepositoryAuthorizedEmail, TagManifest, DerivedStorageForImage,
get_epoch_timestamp, db_random_func)
Label, TagManifestLabel, db_for_update, get_epoch_timestamp,
db_random_func)
logger = logging.getLogger(__name__)
@ -50,11 +51,24 @@ def _purge_all_repository_tags(namespace_name, repository_name):
raise DataModelException('Invalid repository \'%s/%s\'' %
(namespace_name, repository_name))
# Delete all manifests.
# Finds all the tags to delete.
repo_tags = list(RepositoryTag.select().where(RepositoryTag.repository == repo.id))
if not repo_tags:
return
# Find all labels to delete.
labels = list(TagManifestLabel
.select(TagManifestLabel.label)
.where(TagManifestLabel.repository == repo))
# Delete all the mapping entries.
TagManifestLabel.delete().where(TagManifestLabel.repository == repo).execute()
# Delete all the matching labels.
if labels:
Label.delete().where(Label.id << [label.id for label in labels]).execute()
# Delete all the manifests.
TagManifest.delete().where(TagManifest.tag << repo_tags).execute()
# Delete all tags.