我使用azure管道来构建和部署我的docker容器(ASP.Net core 3.1)。 所有步骤均成功完成,我可以在Azure注册表和App Service门户页面上看到我的容器。但是似乎该实例未在App Service上运行,因为我只能看到“开始页面”,这表明我要部署代码,而摇摇欲坠的页面返回404。
所以问题是:如何运行已由管道映像部署的?
我的azure管道yml文件:
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
# run tests
- task: DotNetCoreCLI@2
displayName: Run tests
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: 'ProjectName'
dockerfile: '$(Build.SourcesDirectory)/ProjectName/API/Dockerfile'
buildContext: '$(Build.SourcesDirectory)/ProjectName/'
containerRegistry: AzureContainerRegistryConnection
tags: |
$(tag)
# Deploy stage to your App Service
- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: ubuntu-latest
steps:
- task: AzureWebAppContainer@1
displayName: Deploy to App Service
inputs:
azureSubscription: 'my_free_subscription(my-subscription-id)'
appName: 'app-service'
containers: 'projectnamecontainerregistry.azurecr.io/RepositoryName:$(tag)'
UPD
我不知道这是因为terraform中的应用程序服务设置有问题
resource "azurerm_app_service_plan" "app_service_plab" {
name = "app-service-plan"
location = azurerm_resource_group.store_group.location
resource_group_name = azurerm_resource_group.store_group.name
kind = "Linux"
sku {
tier = "FREE"
size = "S1"
}
}
resource "azurerm_app_service" "app_service" {
name = "app-service"
location = azurerm_resource_group.store_group.location
resource_group_name = azurerm_resource_group.store_group.name
app_service_plan_id = azurerm_app_service_plan.app_service_plab.id
}
UPD2
开始使用新的部署任务AzureRmWebAppDeployment @ 4,它的功能现在甚至可以在应用程序服务计算机上看到日志。
- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: ubuntu-latest
steps:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'free_subscription(id)'
appType: 'webAppContainer'
WebAppName: 'app-service'
DockerNamespace: 'containerregistry.azurecr.io'
DockerRepository: 'myRepository'
DockerImageTag: $(tag)
StartupCommand: 'az acr login --password $(REGISTRY_PASSWORD_UNSECRET) --username $(REGISTRY_USERNAME_UNSECRET) --name (MyRegistry)containerregistry.azurecr.io && docker run'
appSettings: |
-CONNECTION_STRING $(CONNECTION_STRING_UNSECRET)
但是似乎az acr登录不起作用:(
现在我遇到这样的错误
2020-09-19T19:29:08.498Z错误-映像拉取失败:验证Docker映像配置和凭据(如果使用私有存储库) 2020-09-19T19:34:00.826Z信息-从Docker集线器中提取图像:MyContainercontainerregistry.azurecr.io/MyRepo:85 2020-09-19T19:34:01.151Z错误-DockerApiException:Docker API响应,状态码= InternalServerError,响应= {“ message”:“获取https://MyContainercontainerregistry.azurecr.io/v2/MyRepo/manifests/85:未授权:需要身份验证,请访问https://aka.ms/acr/authorization更多信息。“}