Add ability to revert tags via time machine
This commit is contained in:
parent
2a77bd2c92
commit
f19d2f684e
16 changed files with 277 additions and 19 deletions
|
@ -1762,13 +1762,17 @@ def _tag_alive(query, now_ts=None):
|
|||
(RepositoryTag.lifetime_end_ts > now_ts))
|
||||
|
||||
|
||||
def list_repository_tag_history(repository, limit=100):
|
||||
def list_repository_tag_history(repository, limit=100, specific_tag=None):
|
||||
query = (RepositoryTag
|
||||
.select(RepositoryTag, Image)
|
||||
.join(Image)
|
||||
.where(RepositoryTag.repository == repository)
|
||||
.order_by(RepositoryTag.lifetime_start_ts.desc())
|
||||
.limit(limit))
|
||||
|
||||
if specific_tag:
|
||||
query = query.where(RepositoryTag.name == specific_tag)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
|
@ -1990,7 +1994,7 @@ def get_parent_images(namespace_name, repository_name, image_obj):
|
|||
|
||||
|
||||
def create_or_update_tag(namespace_name, repository_name, tag_name,
|
||||
tag_docker_image_id):
|
||||
tag_docker_image_id, reversion=False):
|
||||
try:
|
||||
repo = _get_repository(namespace_name, repository_name)
|
||||
except Repository.DoesNotExist:
|
||||
|
@ -2015,7 +2019,7 @@ def create_or_update_tag(namespace_name, repository_name, tag_name,
|
|||
raise DataModelException('Invalid image with id: %s' % tag_docker_image_id)
|
||||
|
||||
return RepositoryTag.create(repository=repo, image=image, name=tag_name,
|
||||
lifetime_start_ts=now_ts)
|
||||
lifetime_start_ts=now_ts, reversion=reversion)
|
||||
|
||||
def delete_tag(namespace_name, repository_name, tag_name):
|
||||
now_ts = get_epoch_timestamp()
|
||||
|
@ -2823,3 +2827,14 @@ def repository_is_starred(user, repository):
|
|||
return True
|
||||
except Star.DoesNotExist:
|
||||
return False
|
||||
|
||||
|
||||
def revert_tag(namespace_name, repository_name, tag_name, docker_image_id):
|
||||
""" Reverts a tag to a specific image ID. """
|
||||
image = get_image_by_id(namespace_name, repository_name, docker_image_id)
|
||||
if image is None:
|
||||
raise DataModelException('Cannot revert to unknown image')
|
||||
|
||||
return create_or_update_tag(namespace_name, repository_name, tag_name, docker_image_id,
|
||||
reversion=True)
|
||||
|
||||
|
|
Reference in a new issue