azure - 如何使用 Bicep 通过 .Net 堆栈部署 Windows Azure 应用服务?

标签 azure azure-web-app-service azure-resource-manager azure-app-service-plans azure-bicep

我创建了一个 Bicep 来部署服务计划和应用服务,并选择 Linux/Windows 和 .net 6 堆栈。两次部署均成功,Linux 应用程序完全正常,门户网站上存在 .net 6 堆栈。然而,Windows stack门户屏幕上为空。

我使用以下参数:

二头肌Linux参数:

  linuxFxVersion: 'DOTNETCORE|6.0'

二头肌 Windows 参数:

  windowsFxVersion: 'dotnet:6'
  netFrameworkVersion: 'v6.0'

通过此命令,我获得了允许的 Windows 堆栈,因此 dotnet:6 应该没问题

[ ~ ]$ az webapp list-runtimes --os windows --os-type windows
[
  "dotnet:7",
  "dotnet:6",
  "ASPNET:V4.8",
  "ASPNET:V3.5",
  "NODE:18LTS",
...

我可以使用 Powershell 看到我的设置已应用于 Web App .

我尝试了不同的选项,例如 dotnet|6、dotnetcore|6 或不使用 netFrameworkVersion,但没有找到正确的设置。是 Azure 界面错误还是我遗漏了什么? 提前致谢,在下面附上整个二头肌。

@description('Generate unique String for resource names')
param uniqueFullRGString string = uniqueString(resourceGroup().id)

@description('Short unique name based on RG name')
param uniqueRGString string = take(uniqueFullRGString, 4)

@description('Resource group location')
param location string = resourceGroup().location

@description('Azure Tenant Id')
var azureTenantId = tenant().tenantId

@description('App Service Plan OS')
@allowed([
  'linux'
  'windows'
])
param appServicePlanOS string

var linuxOffer = 'linux'
var windowsOffer = 'windows'

@description('App Service Plan SKU')
param appServicePlanSku string = 'F0'

var configReferenceLinux = {
  linuxFxVersion: 'DOTNETCORE|6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

var configReferenceWindows = {
  windowsFxVersion: 'dotnet:6'
  netFrameworkVersion: 'v6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

@description('App Service Plan name')
var appServicePlanName = 'App-${uniqueRGString}'

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  sku: {
    name: appServicePlanSku
  }
  properties: {
      reserved: ((appServicePlanOS == 'linux') ? true : false)
  }
  kind: ((appServicePlanOS == 'linux') ? linuxOffer : windowsOffer)
}

resource appService 'Microsoft.Web/sites@2020-06-01' = {
  name: appServicePlanName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: ((appServicePlanOS == 'linux') ? configReferenceLinux : configReferenceWindows)
  }
  identity: {
    type: 'SystemAssigned'
  }
}

最佳答案

如果您尝试在 Windows 应用程序服务计划上部署 .NET stack webapp,那么您需要添加元数据 block ,用于定义 webapp 的运行时,如本 sample ARM template 中所述。在 Windows 应用服务计划上创建 .NET 应用。

我修改了上面的共享示例二头肌并测试了它是否能够部署 Windows 应用程序服务计划以及在 .NET 堆栈上运行的 Web 应用程序。

@description('Generate unique String for resource names')
param uniqueFullRGString string = uniqueString(resourceGroup().id)

@description('Short unique name based on RG name')
param uniqueRGString string = take(uniqueFullRGString, 4)

@description('Resource group location')
param location string = resourceGroup().location

@description('Azure Tenant Id')
var azureTenantId = tenant().tenantId

@description('App Service Plan OS')
@allowed([
  'linux'
  'windows'
])
param appServicePlanOS string

var linuxOffer = 'linux'
var windowsOffer = 'windows'

@description('App Service Plan SKU')
param appServicePlanSku string = 'F0'

var configReferenceLinux = {
  linuxFxVersion: 'DOTNETCORE|6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

var configReferenceWindows = {
  metadata :[
    {
      name:'CURRENT_STACK'
      value:'dotnet'
    }
  ]
  netFrameworkVersion:'v7.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

@description('App Service Plan name')
var appServicePlanName = 'App-${uniqueRGString}'

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  sku: {
    name: appServicePlanSku
  }
  properties: {
      reserved: ((appServicePlanOS == 'linux') ? true : false)
  }
  kind: ((appServicePlanOS == 'linux') ? linuxOffer : windowsOffer)
}

resource appService 'Microsoft.Web/sites@2020-06-01' = {
  name: appServicePlanName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: ((appServicePlanOS == 'linux') ? configReferenceLinux : configReferenceWindows)
  }
  identity: {
    type: 'SystemAssigned'
  }
}

示例输出屏幕截图供引用:

enter image description here

可以引用这个类似SO thread也是如此。

关于azure - 如何使用 Bicep 通过 .Net 堆栈部署 Windows Azure 应用服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74963001/

相关文章:

Azure 网站缩放

azure - 尝试使用 ARM API 获取 token 时未授权

azure - 使用 linkedtemplate 从 Keyvault 检索密码

node.js - 从 webjob 调用 webapp 中的 API

azure - 是否有适用于 Oracle Fusion ERP 的逻辑应用连接器?

azure - SQL Azure 报告可靠吗?

node.js - 尽管已链接,但从 Azure 静态 Web 应用程序调用应用服务 API 时仍获得未经授权 (401)

node.js - 无法从 Github 存储库将 ASP.NET Core/Angular 应用程序部署到 Azure

Azure RM 模板。如何将变量值引用到资源

powershell - 为什么 Azure 在 PowerShell 命令中找不到预配配置?