gpt4 book ai didi

php - 如何使用yaml模板创建azure容器注册表?

转载 作者:行者123 更新时间:2023-12-03 06:56:02 25 4
gpt4 key购买 nike

我有一个 PHP 应用程序

我正忙于创建 Azure 容器注册表以及构建镜像并将其推送到 Azure 容器注册表的管道。因此,这是构建将镜像推送到 azure 容器注册表的部分:

# Docker
# Build and push an image to Azure Container Registry
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'hackaton_internetsuite_connection'
imageRepository: 'internetsuite-webscraper'
containerRegistry: 'internetsuite.azurecr.io'
dockerfilePath: '**/Dockerfile'
tag: '$(Build.BuildId)'

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)


这是用于创建注册表容器的模板:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"registryName": {
"type": "String"
},
"registryLocation": {
"type": "String"
},
"registrySku": {
"defaultValue": "Standard",
"type": "String"
}
},
"resources": [
{
"type": "Microsoft.ContainerRegistry/registries",
"sku": {
"name": "[parameters('registrySku')]"
},
"name": "[parameters('registryName')]",
"apiVersion": "2017-10-01",
"location": "[parameters('registryLocation')]",
"properties": {
"adminUserEnabled": "true"
}
}
]
}

但现在我想将代码包含在 yaml 文件中以构建 Azure 容器注册表。

那么我必须在 yaml 文件中包含哪些内容才能构建 azure 容器注册表?

我现在是这样的:

# Docker
# Build and push an image to Azure Container Registry
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'hackaton_internetsuite_connection'
imageRepository: 'internetsuite-webscraper'
acrHostName: 'internetsuite.azurecr.io'
dockerfilePath: '**/Dockerfile'
tag: '$(Build.BuildId)'

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)

# Build container image
- task: Docker@1
displayName: 'Build container image'
inputs:
azureSubscriptionEndpoint: 'hackaton_internetsuite_connection'
azureContainerRegistry: '$(acrHostName)'
imageName: '$(imageName):$(Build.BuildId)'
useDefaultContext: false
buildContext: '$(System.DefaultWorkingDirectory)/PublishedWebApp'

# Push container image
- task: Docker@1
displayName: 'Push container image'
inputs:
azureSubscriptionEndpoint: 'hackaton_internetsuite_connection'
azureContainerRegistry: '$(acrHostName)'
command: 'Push an image'
imageName: '$(imageName):$(Build.BuildId)'



我的服务连接的名称是:hackaton_internetsuite_connection

但是我收到了这个错误:

The pipeline is not valid. Job Build: Step Docker2 input azureSubscriptionEndpoint expects a service connection of type AzureRM but the provided service connection hackaton_internetsuite_connection is of type dockerregistry. Job Build: Step Docker3 input azureSubscriptionEndpoint expects a service connection of type AzureRM but the provided service connection hackaton_internetsuite_connection is of type dockerregistry.

最佳答案

从模板示例来看,这是一个 ARM 模板。

在 YAML 示例中,docker 任务用于将 Docker 镜像部署到现有的 Azure 容器注册表。它不会创建新的 Azure 容器注册表。

要部署ARM模板,您需要使用任务:Azure Resource Group Deployment task

例如:

- task: AzureResourceManagerTemplateDeployment@3
displayName: 'ARM Template deployment: Resource Group scope'
inputs:
azureResourceManagerConnection: serviceconnection
subscriptionId: xx
resourceGroupName: xx
location: xx
csmFile: templatefile(template.json)
csmParametersFile: paramtersfile(paramters.json)

对于服务连接,您需要使用Azure Resource Manager类型的服务连接。

例如:

enter image description here

在您的情况下,服务 connect:hackaton_internetsuite_connection 是 Docker 注册表服务连接。这也是您在管道中看到错误的原因。 azureSubscriptionEndpoint字段需要输入Azure Resource Manager类型服务连接。

关于php - 如何使用yaml模板创建azure容器注册表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72953741/

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