def delete_old_tags(self): from azure.containerregistry import ( ContainerRegistryClient, ContainerRepositoryClient, TagOrder ) from azure.identity import DefaultAzureCredential # [START list_repositories] account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(account_url, credential) for repository in client.list_repositories(): repository_client = ContainerRepositoryClient(account_url, repository, credential) # [END list_repositories] # [START list_tags] tag_count = 0 for tag in repository_client.list_tags(order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING): tag_count += 1 if tag_count > 3: repository_client.delete_tag(tag.name) # [END list_tags] client.close()
def basic_sample(self): from azure.containerregistry import ContainerRegistryClient from azure.identity import DefaultAzureCredential # Instantiate the client client = ContainerRegistryClient(self.account_url, DefaultAzureCredential()) with client: # Iterate through all the repositories for repository_name in client.list_repositories(): if repository_name == "hello-world": # Create a repository client from the registry client repository_client = client.get_repository_client(repository_name) with repository_client: # Show all tags for tag in repository_client.list_tags(): print(tag.digest)