![](/img/trans.png)
[英]How to create container azure storage using PHP CURL pre requested code
[英]How to create azure container registry with yaml template?
我有一個 php 應用程序
我正忙於創建 azure 容器注冊表以及構建映像並將其推送到 azure 容器注冊表的管道。 因此,這是構建將映像推送到 azure 容器注冊表的一部分:
# Docker
# Build and push an image to Azure Container Registry
# https://docs.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://docs.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 資源管理器類型的服務連接。
例如:
在您的情況下,服務連接:hackaton_internetsuite_connection 是一個 Docker Registry 服務連接。 這也是您在管道中看到錯誤的原因。 azureSubscriptionEndpoint 字段需要輸入 Azure Resource Manager 類型的服務連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.