我有以下架构: 具有完全用 Bicep 和 Azure-pipelines.yml 编写的 Azure Devops 的 Azure 云 运行 Docker 镜像的边缘系统
我正在尝试找到一种方法,在发生更改时将 Docker 映像从 Azure 容器注册表拉取到本地边缘系统。我想这也许可以通过网络钩子之类的东西来完成。
对于整个工作流程,我将代码推送到我的 Azure 存储库,然后它将该代码构建到 Docker 映像中,并将其推送到我的 Azure 容器注册表,以便将其存储在那里。我的 Azure 云使用该映像在 Azure 云上运行。 我现在想添加第二个管道,它可以为我的 AI 构建代码,并构建它并将其推送到 Azure 容器注册表,以便我的边缘系统可以在更改时从那里提取 docker 映像。
想象一下: AI 代码修改推送到 Azure 容器注册表 --> Edge System 从 Azure 容器注册表提取新的 Docker 映像
我尝试在网上查找资源,但没有找到任何可以解决我的特定问题的资源。
Azure 容器注册表具有 Webhooks。但他们是推动模式。即您的边缘设备/系统需要有一个公共网址 (https),该地址将从 ACR 接收事件。然后您可以响应该事件。
https://learn.microsoft.com/en-us/azure/container-registry/container-registry-webhook
根据您的要求,一旦推送了新图像,就触发第二个管道从 ACR 中提取图像,您可以将 容器资源 添加到 YAML 管道并启用此资源类型的自动触发。
要在边缘系统上拉取映像,您需要在此系统中配置自托管代理服务,并将第二个管道设置为在此代理上运行。这是一个示例 YAML 管道供您参考。
pool: EdgeSystemPool
resources:
containers:
- container: mycontainer1 # name of the container (Alias)
type: ACR # type of registry
azureSubscription: ARMSvcCnnAutoSubX # name of the ARM service connection
resourceGroup: rg-azacr # Azure resource group with the container
registry: azacrxxxxx # Azure container registry name
repository: azuredevops/dockeragent/xxxxx # name of the of container image collection
trigger:
enabled: true
steps:
- script: |
echo "The ACR Container Resource Variables:"
echo $(resources.container.mycontainer1.type)
echo $(resources.container.mycontainer1.registry)
echo $(resources.container.mycontainer1.repository)
echo $(resources.container.mycontainer1.tag)
echo $(resources.container.mycontainer1.digest)
echo $(resources.container.mycontainer1.URI)
echo $(resources.container.mycontainer1.location)
- task: AzureCLI@2
inputs:
azureSubscription: 'ARMSvcCnnAutoSubX'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az acr login --name $(resources.container.mycontainer1.registry)
docker pull $(resources.container.mycontainer1.registry).azurecr.io/$(resources.container.mycontainer1.repository):$(resources.container.mycontainer1.tag)
因此,一旦第一个管道将图像推送到 ACR 存储库,第二个管道将被触发并在边缘系统中的代理上运行
docker pull
命令。
请注意,ARM 服务连接引用的服务主体需要具有 ACR 的贡献者或所有者权限,才能使用自动管道触发器并从 ACR 拉取镜像。