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 )