Merge remote-tracking branch 'origin/spartan'
Conflicts: test/data/test.db
This commit is contained in:
commit
4234ceabe6
10 changed files with 246 additions and 10 deletions
|
@ -755,6 +755,46 @@ def list_repository_tags(namespace_name, repository_name):
|
|||
return with_image.where(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name)
|
||||
|
||||
def delete_tag_and_images(namespace_name, repository_name, tag_name):
|
||||
all_images = get_repository_images(namespace_name, repository_name)
|
||||
all_tags = list_repository_tags(namespace_name, repository_name)
|
||||
|
||||
# Find the tag's information.
|
||||
found_tag = None
|
||||
for tag in all_tags:
|
||||
if tag.name == tag_name:
|
||||
found_tag = tag
|
||||
break
|
||||
|
||||
if not found_tag:
|
||||
return
|
||||
|
||||
# Build the set of database IDs corresponding to the tag's ancestor images, as well as the
|
||||
# tag's image itself.
|
||||
tag_image_ids = set(found_tag.image.ancestors.split('/'))
|
||||
tag_image_ids.add(str(found_tag.image.id))
|
||||
|
||||
# Filter out any images that belong to any other tags.
|
||||
for tag in all_tags:
|
||||
if tag.name != tag_name:
|
||||
# Remove all ancestors of the tag.
|
||||
tag_image_ids = tag_image_ids - set(tag.image.ancestors.split('/'))
|
||||
|
||||
# Remove the current image ID.
|
||||
tag_image_ids.discard(str(tag.image.id))
|
||||
|
||||
# Find all the images that belong to the tag.
|
||||
tag_images = [image for image in all_images if str(image.id) in tag_image_ids]
|
||||
|
||||
# Delete the tag found.
|
||||
found_tag.delete_instance()
|
||||
|
||||
# Delete the images found.
|
||||
for image in tag_images:
|
||||
image.delete_instance()
|
||||
|
||||
# TODO: Delete the image's layer data as well.
|
||||
|
||||
|
||||
def get_tag_image(namespace_name, repository_name, tag_name):
|
||||
joined = Image.select().join(RepositoryTag).join(Repository)
|
||||
|
|
Reference in a new issue