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



我正在使用powershell处理各种CI/CD函数。

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

以下是我迄今为止所做的工作

  1. 构建NodeJS应用程序
  2. 在容器中打包NodeJS应用程序
  3. 将容器发布到专用Azure容器注册表

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

以下是我想弄清楚的

  1. 动态创建应用程序服务计划
  2. 动态创建Web应用程序(容器(
  3. 将容器从ACR拉入应用程序服务

这是我的代码。它似乎不起作用。

$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"

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

下面是发生的事情

当我将插槽切换到我的应用程序进行生产时。

它似乎根本没有显示我的应用程序。

我如何判断它是否上传了我的应用程序?

实际上,我不认为代码中有逻辑问题,而是命令本身的问题。

首先,如果要将PowerShell命令剪切为多行,则需要在除最后一行之外的每行中添加字符`。如果你想获得它,你最好使用相同的网络应用程序名称。所以你想在代码中做一点更改:

$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"

您还需要仔细检查环境变量是否正常存在。

显然这是微软方面的一个错误,不可能通过powershell脚本发布容器。请阅读此处:https://github.com/Azure/azure-powershell/issues/10645

最新更新