def delete_old_tags(self): from azure.containerregistry import ContainerRegistryClient, TagOrder from azure.identity import DefaultAzureCredential # [START list_repository_names] account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(account_url, credential) for repository in client.list_repository_names(): print(repository) # [END list_repository_names] # [START list_tag_properties] # Keep the three most recent tags, delete everything else tag_count = 0 tags = client.list_tag_properties( repository, order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING) for tag in tags[3:]: client.delete_tag(repository, tag.name) # [END list_tag_properties] client.close()
def delete_tags(self): # [START list_repository_names] audience = "https://management.azure.com" account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(account_url, credential, audience=audience) for repository in client.list_repository_names(): print(repository) # [END list_repository_names] # [START list_tag_properties] # Keep the three most recent tags, delete everything else tag_count = 0 for tag in client.list_tag_properties( repository, order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING): tag_count += 1 if tag_count > 3: client.delete_tag(repository, tag.name) # [END list_tag_properties] client.close()