From 6e7f93c4f0522b623450b736848ac6cf55184fe5 Mon Sep 17 00:00:00 2001 From: Roman Skurikhin Date: Wed, 29 Jun 2022 20:18:20 +0300 Subject: [PATCH] Auto remove AWS repos without tags --- platform_registry_api/api.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform_registry_api/api.py b/platform_registry_api/api.py index 9fae8d7f..db4aa5b6 100644 --- a/platform_registry_api/api.py +++ b/platform_registry_api/api.py @@ -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: @@ -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 )