parent
601b741c4e
commit
5941f3937c
5 changed files with 2 additions and 22 deletions
|
@ -62,11 +62,7 @@ def purge_repository(namespace_name, repository_name):
|
||||||
fetched.delete_instance(recursive=True, delete_nullable=False)
|
fetched.delete_instance(recursive=True, delete_nullable=False)
|
||||||
|
|
||||||
|
|
||||||
def find_repository_with_garbage(filter_list=None):
|
def find_repository_with_garbage():
|
||||||
# TODO(jschorr): Remove the filter once we have turned the experiment on for everyone.
|
|
||||||
if filter_list is not None and not filter_list:
|
|
||||||
return None
|
|
||||||
|
|
||||||
epoch_timestamp = get_epoch_timestamp()
|
epoch_timestamp = get_epoch_timestamp()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -80,9 +76,6 @@ def find_repository_with_garbage(filter_list=None):
|
||||||
.limit(500)
|
.limit(500)
|
||||||
.alias('candidates'))
|
.alias('candidates'))
|
||||||
|
|
||||||
if filter_list:
|
|
||||||
candidates = candidates.where(Namespace.username << filter_list)
|
|
||||||
|
|
||||||
found = (RepositoryTag
|
found = (RepositoryTag
|
||||||
.select(candidates.c.repository_id)
|
.select(candidates.c.repository_id)
|
||||||
.from_(candidates)
|
.from_(candidates)
|
||||||
|
@ -100,11 +93,6 @@ def find_repository_with_garbage(filter_list=None):
|
||||||
|
|
||||||
|
|
||||||
def garbage_collect_repository(namespace_name, repository_name):
|
def garbage_collect_repository(namespace_name, repository_name):
|
||||||
# If the namespace is the async experiment, don't perform garbage collection here.
|
|
||||||
# TODO(jschorr): Remove this check once we have turned the experiment on for everyone.
|
|
||||||
if namespace_name in config.app_config.get('EXP_ASYNC_GARBAGE_COLLECTION', []):
|
|
||||||
return
|
|
||||||
|
|
||||||
repo = get_repository(namespace_name, repository_name)
|
repo = get_repository(namespace_name, repository_name)
|
||||||
if repo is not None:
|
if repo is not None:
|
||||||
garbage_collect_repo(repo)
|
garbage_collect_repo(repo)
|
||||||
|
|
|
@ -105,7 +105,6 @@ class RepositoryTag(RepositoryParamResource):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
model.tag.create_or_update_tag(namespace, repository, tag, image_id)
|
model.tag.create_or_update_tag(namespace, repository, tag, image_id)
|
||||||
model.repository.garbage_collect_repository(namespace, repository)
|
|
||||||
|
|
||||||
username = get_authenticated_user().username
|
username = get_authenticated_user().username
|
||||||
log_action('move_tag' if original_image_id else 'create_tag', namespace,
|
log_action('move_tag' if original_image_id else 'create_tag', namespace,
|
||||||
|
@ -120,7 +119,6 @@ class RepositoryTag(RepositoryParamResource):
|
||||||
def delete(self, namespace, repository, tag):
|
def delete(self, namespace, repository, tag):
|
||||||
""" Delete the specified repository tag. """
|
""" Delete the specified repository tag. """
|
||||||
model.tag.delete_tag(namespace, repository, tag)
|
model.tag.delete_tag(namespace, repository, tag)
|
||||||
model.repository.garbage_collect_repository(namespace, repository)
|
|
||||||
|
|
||||||
username = get_authenticated_user().username
|
username = get_authenticated_user().username
|
||||||
log_action('delete_tag', namespace,
|
log_action('delete_tag', namespace,
|
||||||
|
@ -193,7 +191,6 @@ class RevertTag(RepositoryParamResource):
|
||||||
# Revert the tag back to the previous image.
|
# Revert the tag back to the previous image.
|
||||||
image_id = request.get_json()['image']
|
image_id = request.get_json()['image']
|
||||||
model.tag.revert_tag(tag_image.repository, tag, image_id)
|
model.tag.revert_tag(tag_image.repository, tag, image_id)
|
||||||
model.repository.garbage_collect_repository(namespace, repository)
|
|
||||||
|
|
||||||
# Log the reversion.
|
# Log the reversion.
|
||||||
username = get_authenticated_user().username
|
username = get_authenticated_user().username
|
||||||
|
|
|
@ -236,9 +236,6 @@ def update_images(namespace, repository):
|
||||||
# Make sure the repo actually exists.
|
# Make sure the repo actually exists.
|
||||||
abort(404, message='Unknown repository', issue='unknown-repo')
|
abort(404, message='Unknown repository', issue='unknown-repo')
|
||||||
|
|
||||||
logger.debug('GCing repository')
|
|
||||||
model.repository.garbage_collect_repository(namespace, repository)
|
|
||||||
|
|
||||||
# Generate a job for each notification that has been added to this repo
|
# Generate a job for each notification that has been added to this repo
|
||||||
logger.debug('Adding notifications for repository')
|
logger.debug('Adding notifications for repository')
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,6 @@ def delete_tag(namespace, repository, tag):
|
||||||
|
|
||||||
if permission.can():
|
if permission.can():
|
||||||
model.tag.delete_tag(namespace, repository, tag)
|
model.tag.delete_tag(namespace, repository, tag)
|
||||||
model.repository.garbage_collect_repository(namespace, repository)
|
|
||||||
|
|
||||||
return make_response('Deleted', 200)
|
return make_response('Deleted', 200)
|
||||||
|
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
|
@ -15,7 +15,7 @@ class GarbageCollectionWorker(Worker):
|
||||||
def _garbage_collection_repos(self):
|
def _garbage_collection_repos(self):
|
||||||
""" Performs garbage collection on repositories. """
|
""" Performs garbage collection on repositories. """
|
||||||
with UseThenDisconnect(app.config):
|
with UseThenDisconnect(app.config):
|
||||||
repository = find_repository_with_garbage(app.config.get('EXP_ASYNC_GARBAGE_COLLECTION', []))
|
repository = find_repository_with_garbage()
|
||||||
if repository is None:
|
if repository is None:
|
||||||
logger.debug('No repository with garbage found')
|
logger.debug('No repository with garbage found')
|
||||||
return
|
return
|
||||||
|
|
Reference in a new issue