首页 > 解决方案 > 在二头肌模板上设置 Azure 应用服务服务器堆栈

问题描述

我正在尝试使用 Azure CLI 中的 Bicep 模板在 Linux 上部署 .NET Core 3.1 Azure App Service。应用服务和相应的应用服务计划已正确部署,但 Azure 门户上的应用服务堆栈设置为空,我必须手动设置这些设置。我尝试在“Microsoft.Web/sites”资源和“Microsoft.Web/sites/config”资源上设置元数据属性,但结果是一样的。

这是我的应用服务计划:

resource appServicePlan 'Microsoft.Web/serverfarms@2021-02-01' = {
  name: 'MyAppService'
  location: resourceGroup().location
  properties: {
    reserved: true
  }
  sku: {
    name: 'P1v2'
  }
  kind: 'linux'
}

这是我第一次尝试使用此处建议的“Microsoft.Web/sites”设置堆栈:

https://github.com/Azure/bicep/issues/3314

resource appService 'Microsoft.Web/sites@2021-02-01' = {
  name: 'MyApp'
  location: resourceGroup().location
  identity: {
    type: 'SystemAssigned'
  }
  kind: 'app'
  properties: {
    enabled: true
    serverFarmId: appServicePlan.id
    siteConfig: {
      linuxFxVersion: 'dotnet|3.1'
      appCommandLine: 'dotnet MyApp.dll'
      metadata: [
        {
          name: 'CURRENT_STACK'
          value: 'dotnetcore'
        }
      ]
    }
  }
}

这是我第二次尝试使用此处建议的“Microsoft.Web/sites/config”设置堆栈:

Bicep - 如何将运行时堆栈配置到 Azure 应用服务(Bicep 版本 0.4)

resource appService 'Microsoft.Web/sites@2021-02-01' = {
  name: 'MyApp'
  location: resourceGroup().location
  identity: {
    type: 'SystemAssigned'
  }
  kind: 'app'
  properties: {
    enabled: true
    serverFarmId: appServicePlan.id
    siteConfig: {
      linuxFxVersion: 'dotnet|3.1'
      appCommandLine: 'dotnet MyApp.dll'
    }
  }
  resource webConfig 'config' = {
    name: 'web'
    properties: {
      metadata: [
        {
          name: 'CURRENT_STACK'
          value: 'dotnetcore'
        }
      ]
    }
  }
}

结果是一样的。部署完成并出现以下警告:

警告 BCP037:“SiteConfig”类型的对象不允许使用“元数据”属性。允许的属性包括“acrUseManagedIdentityCreds”、“acrUserManagedIdentityID”、“alwaysOn”、“apiDefinition”、“apiManagementConfig”、“autoHealEnabled”、“autoHealRules”、“autoSwapSlotName”、“azureStorageAccounts”、“connectionStrings”、“cors”、“defaultDocuments” 、“detailedErrorLoggingEnabled”、“documentRoot”、“experiments”、“ftpsState”、“functionAppScaleLimit”、“functionsRuntimeScaleMonitoringEnabled”、“handlerMappings”、“healthCheckPath”、“http20Enabled”、“httpLoggingEnabled”、“ipSecurityRestrictions”、“

资源已部署,但应用服务堆栈设置为空白,我必须手动设置才能使其正常工作。

应用服务堆栈设置

我知道在 ARM 模板中,这是在 Microsoft.Web/sites/config 元数据的 CURRENT_STACK 属性上设置的(如此处建议的https://cloudstep.io/2020/11/18/undocumented-arm-oddities-net-核心应用服务/)。但是,二头肌似乎(尚)不支持此功能。如果有人找到了可行的解决方案,请在此处发布。谢谢。

标签: azure-web-app-serviceazure-bicep

解决方案


Metadata 参数在SiteConfig. 可以提到堆栈设置LinuxFxVersion

因此,解决方案将不是使用dotnet|3.1,而是应该使用DOTNETCORE|3.1。所有代码如下:

resource appServicePlan 'Microsoft.Web/serverfarms@2021-02-01' = {
  name: 'MyAppService'
  location: resourceGroup().location
  properties: {
    reserved: true
  }
  sku: {
    name: 'P1v2'
  }
  kind: 'linux'
}
resource appService 'Microsoft.Web/sites@2021-02-01' = {
  name: 'anumantestapp'
  location: resourceGroup().location
  identity: {
    type: 'SystemAssigned'
  }
  kind: 'app'
  properties: {
    enabled: true
    serverFarmId: appServicePlan.id
    siteConfig: {
      linuxFxVersion: 'DOTNETCORE|3.1'
      appCommandLine: 'dotnet MyApp.dll'
    }
  }
}

输出:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述


推荐阅读