gpt4 book ai didi

python - 如何使用 ContainerRegistryClient 将标签添加到 Azure 容器注册表中的 list ?

转载 作者:行者123 更新时间:2023-12-03 06:47:34 24 4
gpt4 key购买 nike

我需要使用 ContainerRegistryClient 将标签添加到 Azure 容器注册表中的 list

我正在尝试使用以下代码。我获取当前标签列表,假设 ["V1"] 并附加 "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)

我没有收到任何错误,也没有任何反馈。如果我打印 prop._tags,我可以看到新标签。但是,如果我检查 Azure 门户,该标签不存在。另外,通过读取list_manifest_properties中的manifest.tags,我看不到“V2”标签。

我该如何应用更新的属性?

最佳答案

我在我的环境中尝试并得到了以下结果

我在我的环境中执行了相同的代码并获得了相同的标签

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)

控制台: enter image description here

执行后,我得到了一个输出(标签),它存在于容器注册表(存储库)中。

我检查了这个Document它告诉update_manifest_properties。他们正在使用更新

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

它表明您可以更新 list 中的特定命令。

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

是的,您可以使用以下脚本通过 Powershell 添加标签。

脚本:

 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`

门户: enter image description here

控制台:

我添加了两个标签,例如 v2 和 abc123。

enter image description here

门户:

enter image description here

引用:

Azure Container Registry ACR How to add tag to image?作者:阿类·阳光

关于python - 如何使用 ContainerRegistryClient 将标签添加到 Azure 容器注册表中的 list ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73975369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com