0

I need to add a tag to a manifest in Azure Container Registry, using ContainerRegistryClient

I'm trying with the following code. I get the current tags list, let's say ["V1"] and I append "V2".

tag_to_update = "V1"
new_tag = "V2"
client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience)
properties = client.get_manifest_properties(repository="cr_name", tag_or_digest=tag_to_update)
properties._tags.append(new_tag)
prop = client.update_manifest_properties("cr_name", tag_to_update, properties)

I get no error and no feedback. If I print prop._tags, I can see the new tag. However if I check on Azure Portal, the tag is not there. Also by reading manifest.tags, in list_manifest_properties, I cannot see the "V2" tag.

How am I suppose to apply the updated properties?

HAL9000
  • 3,562
  • 3
  • 25
  • 47

1 Answers1

1

I tried in my environment and got below results

I executed same code on my environment and got same tag

from  azure.containerregistry  import  ContainerRegistryClient
from  azure.identity  import  DefaultAzureCredential

endpoint = "https://registry3261.azurecr.io"
audience="https://management.azure.com"

tag_to_update = "v1"
new_tag = "v2"
client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience)
properties = client.get_manifest_properties(repository="hello-world", tag_or_digest=tag_to_update)
properties._tags.append(new_tag)
prop = client.update_manifest_properties("hello-world", tag_to_update, properties)
print(prop.tags)

Console: enter image description here

After executing I got an output(tag) which is present in the container registry(repository).

I checked this Document it tells update_manifest_properties. they were using to update

        "my_repository",
        artifact.digest,
        can_delete=False,
        can_list=False,
        can_read=False,
        can_write=False,

It shows you can update the particular commands in manifest.

How to add a tag to a manifest in Azure Container Registry?

Yes, you can add the tags by Powershell by using below script.

Script:

 Connect-AzContainerRegistry -Name < registry name >
 $srImage= "acrloginserver/repository:old-tag";
 $newtag= "acrloginserver/repository:latest-tag"
 docker pull $srImage
 docker tag $srImage $newtag
 docker push $newtag`

Portal: enter image description here

Console:

I have added two tags like v2 and abc123.

enter image description here

Portal:

enter image description here

Reference:

Azure Container Registry ACR How to add tag to image? by abann sunny

Venkatesan
  • 3,748
  • 1
  • 3
  • 15
  • 1
    Thanks, I upvoted, because you proposed a workaround in Powershell. However, I guess this means it cannot be done directly by the Python package. – HAL9000 Oct 17 '22 at 08:09