在 Bicep 模板上设置 Azure App Service 服务器堆栈

Setting Azure App Service server stack on a Bicep template

我正在尝试使用 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' 设置堆栈:

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'
        }
      ]
    }
  }
}

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

Warning BCP037: The property "metadata" is not allowed on objects of type "SiteConfig". Permissible properties include "acrUseManagedIdentityCreds", "acrUserManagedIdentityID", "alwaysOn", "apiDefinition", "apiManagementConfig", "autoHealEnabled", "autoHealRules", "autoSwapSlotName", "azureStorageAccounts", "connectionStrings", "cors", "defaultDocuments", "detailedErrorLoggingEnabled", "documentRoot", "experiments", "ftpsState", "functionAppScaleLimit", "functionsRuntimeScaleMonitoringEnabled", "handlerMappings", "healthCheckPath", "http20Enabled", "httpLoggingEnabled", "ipSecurityRestrictions", "javaContainer", "javaContainerVersion", "javaVersion", "keyVaultReferenceIdentity", "limits", "loadBalancing", "localMySqlEnabled", "logsDirectorySizeLimit", "managedPipelineMode", "managedServiceIdentityId", "minimumElasticInstanceCount", "minTlsVersion", "netFrameworkVersion", "nodeVersion", "numberOfWorkers", "phpVersion", "powerShellVersion", "preWarmedInstanceCount", "publicNetworkAccess", "publishingUsername", "push", "pythonVersion", "remoteDebuggingEnabled", "remoteDebuggingVersion", "requestTracingEnabled", "requestTracingExpirationTime", "scmIpSecurityRestrictions", "scmIpSecurityRestrictionsUseMain", "scmMinTlsVersion", "scmType", "tracingOptions", "use32BitWorkerProcess", "virtualApplications", "vnetName", "vnetPrivatePortsCount", "vnetRouteAllEnabled", "websiteTimeZone", "webSocketsEnabled", "windowsFxVersion", "xManagedServiceIdentityId". If this is an inaccuracy in the documentation, please report it to the Bicep Team. [https://aka.ms/bicep-type-issues]

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

我知道在 ARM 模板中,这是在 Microsoft 的 CURRENT_STACK 属性 中设置的。Web/sites/config 元数据(如此处建议 https://cloudstep.io/2020/11/18/undocumented-arm-oddities-net-core-app-services/)。然而,这在 Bicep 中似乎还不被支持。如果有人找到了可行的解决方案,请在此处 post。 谢谢。

元数据参数在 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'
    }
  }
}

输出: