Skip to content

Commit

Permalink
Auto remove AWS repos without tags
Browse files Browse the repository at this point in the history
  • Loading branch information
romasku committed Jun 29, 2022
1 parent 49e47e5 commit 6e7f93c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions platform_registry_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ async def _handle_aws_ecr_tags_list(
) -> Response:
_, _, user, *repository_components, _, _ = request.path.split("/")
repository = "/".join(repository_components)
aws_repository = f"{self._upstream_registry_config.project}/{user}/{repository}"
args = {
"repositoryName": f"{self._upstream_registry_config.project}/"
f"{user}/{repository}",
"repositoryName": aws_repository,
"filter": {"tagStatus": "TAGGED"},
}
if "next" in registry_repo_url.url.query:
Expand All @@ -553,6 +553,13 @@ async def _handle_aws_ecr_tags_list(
client_response = await client.list_images(**args)
logger.debug("upstream response: %s", client_response)

if (
len(client_response.get("imageIds", [])) == 0
and "next" not in registry_repo_url.url.query
):
# This is repo without tags, lets clean up it
await self._delete_aws_ecr_repository(aws_repository)

response_headers = self._prepare_response_headers(
client_response["ResponseMetadata"]["HTTPHeaders"], url_factory
)
Expand Down

0 comments on commit 6e7f93c

Please sign in to comment.