简体   繁体   English

Powershell + Azure 应用服务 + Azure 容器注册表

[英]Powershell + Azure App Service + Azure Container Registry

I am using powershell to handle various CI/CD functions.我正在使用 powershell 来处理各种 CI/CD 功能。

============================================= ==============================================

Here is what I have done so far.这是我到目前为止所做的。

  1. Build NodeJS App构建 NodeJS 应用程序
  2. Package NodeJS App in Container容器中的 Package NodeJS 应用程序
  3. Publish Container to Private Azure Container Registry将容器发布到私有 Azure 容器注册表

============================================= ==============================================

Here is what I am trying to figure out.这是我想要弄清楚的。

  1. Create App Service Plan on the Fly即时创建应用服务计划
  2. Create Web App (Container) on the Fly即时创建 Web 应用程序(容器)
  3. Pull in Container from ACR into App Service将容器从 ACR 拉入应用服务

Here is my code.这是我的代码。 It doesn't seem to be working.它似乎不起作用。

$azureContainerCredential = Get-AzContainerRegistryCredential -ResourceGroupName $env:AZURE_CONTAINER_REGISTRY_RESOURCE_GROUP -Name $env:AZURE_CONTAINER_REGISTRY_NAME
$azureSecuredPassword = ConvertTo-SecureString $azureContainerCredential.Password -AsPlainText -Force

$azureContainerRegistry = Get-AzContainerRegistry -ResourceGroupName $env:AZURE_CONTAINER_REGISTRY_RESOURCE_GROUP

$azureAppServicePlan = Get-AzAppServicePlan -ResourceGroupName "amlihelloworld" -Name "amlihelloworld-app-service-plan"

if($null -eq $azureAppServicePlan)
{
  "==============================================================================="
   Write-Output  "CREATING HELLO WORLD WEB APPLICATION"

   $azureAppServicePlan = New-AzAppServicePlan -Name "amlihelloworld-app-service-plan" -Location "Central 
   US" -ResourceGroupName "amlihelloworld" -Tier Standard

   $azureApp = New-AzWebApp -ResourceGroupName "amlihelloworld" -Name "amlihelloworld2" -AppServicePlan 
   $azureAppServicePlan.Name -ContainerImageName "amlihelloworld:20200422.7" -ContainerRegistryPassword 
   $azureSecuredPassword  -ContainerRegistryUrl $azureContainerRegistry.LoginServer - 
     ContainerRegistryUser $azureContainerCredential.Username

   $azureAppSlot = New-AzWebAppSlot -Name $azureApp.Name  -ResourceGroupName "amlihelloworld" -Slot 
    "development"
}

$azureApp1 = Get-AzWebApp -ResourceGroupName "amlihelloworld" -Name "amlihelloworld"

============================================= ==============================================

Here is whats happening这是发生的事情

When I switch the slots to my app for production.当我将插槽切换到我的应用程序进行生产时。

It doesn't seem to be showing my app at all.它似乎根本没有显示我的应用程序。

How can I tell if it uploaded my app or not?我怎么知道它是否上传了我的应用程序?

Actually, I don't think there is a logic problem in the code, but a problem for the commands itself.实际上,我不认为代码中存在逻辑问题,而是命令本身存在问题。

First, if you want to cut the PowerShell command into multiple lines, you need to add the character ` append each line except the last one.首先,如果要将PowerShell命令切割成多行,则需要在除最后一行之外的每一行添加字符` append。 And you'd better use the same web app name if you want to get it.如果你想得到它,你最好使用相同的 web 应用程序名称。 So you'd like to make a little change in your code:所以你想对你的代码做一点改动:

$azureContainerCredential = Get-AzContainerRegistryCredential -ResourceGroupName $env:AZURE_CONTAINER_REGISTRY_RESOURCE_GROUP -Name $env:AZURE_CONTAINER_REGISTRY_NAME
$azureSecuredPassword = ConvertTo-SecureString $azureContainerCredential.Password -AsPlainText -Force

$azureContainerRegistry = Get-AzContainerRegistry -ResourceGroupName $env:AZURE_CONTAINER_REGISTRY_RESOURCE_GROUP

$azureAppServicePlan = Get-AzAppServicePlan -ResourceGroupName "amlihelloworld" -Name "amlihelloworld-app-service-plan"

if($null -eq $azureAppServicePlan)
{
  "==============================================================================="
   Write-Output  "CREATING HELLO WORLD WEB APPLICATION"

   $azureAppServicePlan = New-AzAppServicePlan -Name "amlihelloworld-app-service-plan" -Location "Central 
   US" -ResourceGroupName "amlihelloworld" -Tier Standard

   $azureApp = New-AzWebApp -ResourceGroupName "amlihelloworld" -Name "amlihelloworld2" `
   -AppServicePlan $azureAppServicePlan.Name `
   -ContainerImageName "amlihelloworld:20200422.7" `
   -ContainerRegistryPassword $azureSecuredPassword  `
   -ContainerRegistryUrl $azureContainerRegistry.LoginServer `
   -ContainerRegistryUser $azureContainerCredential.Username

   $azureAppSlot = New-AzWebAppSlot -Name $azureApp.Name  -ResourceGroupName "amlihelloworld" -Slot 
    "development"
}

$azureApp1 = Get-AzWebApp -ResourceGroupName "amlihelloworld" -Name "amlihelloworld2"

You also need to check carefully if your environment variables exist as normal.您还需要仔细检查您的环境变量是否正常存在。

Apparently it's a bug on Microsoft side and it's not possible to publish containers through powershell scripts.显然这是微软方面的一个错误,无法通过 powershell 脚本发布容器。 Please read here: https://github.com/Azure/azure-powershell/issues/10645请在此处阅读: https://github.com/Azure/azure-powershell/issues/10645

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure容器注册表中的Azure App Service连续部署 - Azure App Service continuous deployment from Azure Container Registry Azure APP服务。+私有链接+ Azure容器注册表 - Azure APP Service.+ Private Link + Azure Container Registry Azure 应用服务私有容器注册表登录问题 - Azure app service private container registry login problem Azure 容器注册表授权 Azure Web 应用程序 - Azure Container Registry authorization for Azure Web App Docker 通过服务原理登录到 Azure 容器注册表 - Docker login to Azure Container Registry by Service Principle 通过 Terraform 中 azure 应用服务的角色分配访问 azure 容器注册表 (ACR) - Access azure container registry (ACR) by role assignment for azure app service in Terraform Pulumi:添加Azure Web App Service web hook到Azure Container Registry进行持续部署 - Pulumi: Add Azure Web App Service web hook to Azure Container Registry for continuous deployment 使用 CLI 将 Azure Web 应用程序(容器)连接到 Azure 容器注册表 - Connecting an Azure Web app (container) to an Azure container registry using the CLI 如何从 GitLab 容器注册表将 Docker 容器部署到 Azure 应用服务 - How to deploy a Docker container to Azure App Service from GitLab container registry 从Azure Kubernetes Service使用Azure容器注册表进行身份验证时发出的问题 - Issue of while Authenticate with Azure Container Registry from Azure Kubernetes Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM