恒美微站
首页
关于我们
建站服务
主题模板
案例展示
资讯中心
联系我们
【研发类-框架和库Skills】azure-containerregistry-py 技能
首页
资讯中心
/
【研发类-框架和库Skills】azure-containerregistry-py 技能
【研发类-框架和库Skills】azure-containerregistry-py 技能
发布时间:2026/8/14 14:10:31
Azure Container Registry SDK for Python。用于管理容器镜像、制品和仓库。技能概述azure-containerregistry-py 技能提供了Azure Container Registry SDK for Python的完整使用指南。该技能帮助开发者管理Azure容器注册表中的容器镜像、制品和仓库支持仓库操作、标签管理、清单操作和制品上传下载等功能。下载地址agentic-awesome-skills/skills/azure-containerregistry-py at main · sickn33/agentic-awesome-skills · GitHub主要功能仓库管理: 列出、获取和删除容器镜像仓库标签操作: 列出、获取和删除镜像标签清单管理: 列出、获取、更新和删除镜像清单制品操作: 下载和上传容器制品权限管理: 设置镜像的读写和删除权限异步客户端: 支持异步操作提高性能触发条件在以下情况下应该调用此技能:需要管理Azure容器注册表中的镜像实现容器镜像的清理和维护管理容器镜像标签和清单下载或上传容器制品设置容器镜像的访问权限安装方法pip install azure-containerregistry环境变量AZURE_CONTAINERREGISTRY_ENDPOINThttps://registry-name.azurecr.io使用示例示例1: 创建客户端from azure.containerregistry import ContainerRegistryClientfrom azure.identity import DefaultAzureCredential# 使用Entra ID推荐client ContainerRegistryClient(endpointos.environ[AZURE_CONTAINERREGISTRY_ENDPOINT],credentialDefaultAzureCredential())# 匿名访问公共注册表client ContainerRegistryClient(endpointhttps://mcr.microsoft.com,credentialNone,audiencehttps://mcr.microsoft.com)示例2: 列出仓库和标签# 列出所有仓库for repository in client.list_repository_names():print(repository)# 列出标签for tag in client.list_tag_properties(my-image):print(f{tag.name}: {tag.created_on})# 按顺序过滤from azure.containerregistry import ArtifactTagOrderfor tag in client.list_tag_properties(my-image,order_byArtifactTagOrder.LAST_UPDATED_ON_DESCENDING):print(f{tag.name}: {tag.last_updated_on})示例3: 清单操作# 列出清单from azure.containerregistry import ArtifactManifestOrderfor manifest in client.list_manifest_properties(my-image,order_byArtifactManifestOrder.LAST_UPDATED_ON_DESCENDING):print(fDigest: {manifest.digest})print(fTags: {manifest.tags})print(fSize: {manifest.size_in_bytes})# 获取清单属性manifest client.get_manifest_properties(my-image, latest)print(fDigest: {manifest.digest})print(fArchitecture: {manifest.architecture})print(fOS: {manifest.operating_system})# 删除清单client.delete_manifest(my-image, sha256:abc123...)示例4: 清理旧镜像from datetime import datetime, timedelta, timezonecutoff datetime.now(timezone.utc) - timedelta(days30)for manifest in client.list_manifest_properties(my-image):if manifest.last_updated_on cutoff and not manifest.tags:print(fDeleting {manifest.digest})client.delete_manifest(my-image, manifest.digest)示例5: 异步客户端from azure.containerregistry.aio import ContainerRegistryClientfrom azure.identity.aio import DefaultAzureCredentialasync def list_repos():credential DefaultAzureCredential()client ContainerRegistryClient(endpoint, credential)async for repo in client.list_repository_names():print(repo)await client.close()await credential.close()客户端操作操作描述list_repository_names列出所有仓库get_repository_properties获取仓库元数据delete_repository删除仓库及所有镜像list_tag_properties列出仓库中的标签get_tag_properties获取标签元数据delete_tag删除特定标签list_manifest_properties列出仓库中的清单get_manifest_properties获取清单元数据delete_manifest按摘要删除清单download_manifest下载清单内容download_blob下载层blob最佳实践使用Entra ID: 生产环境中使用Entra ID进行身份验证按摘要删除: 不要按标签删除以避免孤立镜像锁定生产镜像: 使用can_deleteFalse保护生产镜像定期清理未标记清单: 定期清理未标记的清单使用异步客户端: 用于高吞吐量操作按last_updated排序: 查找最近/旧的镜像删除前检查manifest.tags: 避免删除已标记的镜像限制说明仅当任务明确符合上述范围时使用此技能不要将输出视为环境特定验证、测试或专家审查的替代品如果缺少所需的输入、权限、安全边界或成功标准请停止并寻求澄清