首页 > 解决方案 > ARM 模板:如何确保 Web 应用程序插槽不会部署 Web 应用程序设置?

问题描述

我在 Azure 上为我们的暂存和生产环境提供了完整的 ARM 模板。它通过 Azure DevOps 发布。

但是,我注意到我在我的 ARM 中为 Web App 应用的 Web App 设置,它也复制到了 Web App Slots。我知道这可以在 Azure 上手动勾选,但是有没有办法在 ARM 模板上做到这一点?我查看了 Microsoft 网站,但没有看到任何帮助,并且想知道这是否是手动任务?

{
        "type": "Microsoft.Web/sites/config",
        "apiVersion": "2019-08-01",
        "location": "[resourceGroup().location]",
        "name": "[concat(parameters('webAppName'), '/appsettings')]",
        "dependsOn": [
            "[parameters('webAppName')]",
            "[concat(parameters('sqlDatabase'), 'constr')]"
        ],
        "properties": {
            "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsights')), '2014-04-01').InstrumentationKey]",
            "ApplicationInsightsAgent_EXTENSION_VERSION": "~2",
            "DiagnosticServices_EXTENSION_VERSION": "~3",
}

这就是我的应用程序设置代码的样子(还有更多应用程序设置,我不需要全部复制)

下面是我的 Web App Slots ARM 代码

{
        "apiVersion": "2019-08-01",
        "type": "Microsoft.Web/sites/slots",
        "name": "[concat(parameters('webAppName'), '/', parameters('slots')[copyIndex()])]",
        "kind": "app",
        "location": "[resourceGroup().location]",
        "copy": {
            "name": "WebAppSlots",
            "count": "[length(parameters('slots'))]"
        },
        "properties": {
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('planName'))]"
        },
        "dependsOn": [
            "[parameters('webAppName')]",
            "[concat(parameters('sqlDatabase'), 'constr')]"
        ]
    },

我真的很感激任何关于这个问题的见解。

谢谢 :)

标签: jsonazureweb-applicationsazure-devopsazure-resource-manager

解决方案


使用 ARM 模板的插槽设置非常痛苦。在 ARM 模板中没有办法在不实际复制插槽定义中的属性部分的情况下复制设置。

由于您使用 Azure DevOps 进行部署,因此您可以使用更多选项。在我的脑海中,这些包括:

  • 使用Azure 应用服务设置任务将 Web 应用和插槽设置设置为管道的一部分。
  • 使用Azure App Configuration Service我很幸运。这将需要您编写一些代码,但我喜欢配置历史跟踪、比较以及无需回收 Web 应用即可热插拔设置的能力。
  • 我还刚刚在部署管道中执行了 Powershell 脚本,以设置 Azure Web App 和 Slot 设置。有了上述方法的可用性,我想说这是一个遥远的三分之一。但为了完整起见,我想包括它。

推荐阅读