9

我正在尝试进入该 Visual Studio 资源组模板。到目前为止它看起来不错,我已经为 Web 应用程序添加了一些应用程序设置,但我的问题是,我怎样才能使它们成为特定的部署槽?模板或参数文件的 json 中有什么东西吗?

4

4 回答 4

14

接受的答案是正确的,但遗漏了一条重要信息。在其当前实现下,当交换插槽时,插槽的 AppSettings 配置将与部署一起交换。如果您担心特定于插槽的配置,那么这可能不适合您。

要将配置“粘”到插槽,请在 ARM 模板中使用以下资源。请注意,slotconfignames部分已添加到上面汤姆回答的 ARM 模板片段中。

"resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "appsettings",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
          ],
          "properties": {
            "AppSettingKey1": "Some staging value",
            "AppSettingKey2": "My second staging setting",
            "AppSettingKey3": "My third staging setting"
          },
      {
        "apiVersion": "2015-08-01",
        "name": "slotconfignames",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
        ],
        "properties": {
          "appSettingNames": [ "AppSettingKey1", "AppSettingKey2" ]
        }
      }
    ]

这将使 AppSettingKey1 和 AppSettingKey2 粘到 Staging 插槽(它们不会与部署一起交换)。

有关粘滞槽设置以及其他 ARM 模板提示的更多详细信息,请参阅Anthony Chu 的“Azure 资源管理器模板提示和技巧” 。

于 2017-06-05T14:22:26.590 回答
10

请尝试添加 ARM 模板中剪切的 json 代码。我已经测试过了。它成功地工作。

 "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "appsettings",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
          ],
          "properties": {
            "AppSettingKey1": "Some staging value",
            "AppSettingKey2": "My second staging setting",
            "AppSettingKey3": "My third staging setting"
          }
        }
      ]

以下是我的详细步骤:

1.新建Azure资源组项目(详细请参考文档

在此处输入图像描述

2. Demo 仅用于 Azure Website Slot App 设置配置,因此请从项目中删除其他资源。

在此处输入图像描述

3.将Slot配置添加到部署文件中 在此处输入图像描述

4. 发布部署  

在此处输入图像描述

完整的 json 代码:

  {
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "S1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "dependsOn": [
        "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "location": "[resourceGroup().location]",
      "name": "[variables('webSiteName')]",
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Staging",
          "type": "slots",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
          },
          "resources": [
            {
              "apiVersion": "2015-08-01",
              "name": "appsettings",
              "type": "config",
              "dependsOn": [
                "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
              ],
              "properties": {
                "AppSettingKey1": "Some staging value",
                "AppSettingKey2": "My second staging setting",
                "AppSettingKey3": "My third staging setting"
              }
            }
          ]
        }

      ],
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "type": "Microsoft.Web/sites"
    }
  ]
}

如果 Azure 门户上有任何插槽, 我们也可以从azure 资源中获取插槽类型。在此处输入图像描述 我还在 SO 中找到了类似的线程

于 2016-10-31T13:07:10.013 回答
2

“slotconfignames”只能在生产槽上指定,以告知哪些设置是特定于槽的,即使它们甚至不存在于槽上。插槽特定设置的实际值仍应在插槽设置中指定。

"resources": [
{
  "apiVersion":"[variables('siteApiVersion')]",
  "name":"[variables('WebAppName')]",
  "type":"Microsoft.Web/sites",
  "kind":"api",
  "location":"[variables('location')]",      
  "tags":{
     "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]":"empty"
  },
  "properties":{
     "name":"[variables('WebAppName')]",
     "serverFarmId":"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
     "siteConfig":{
        "AlwaysOn":"[parameters('AppServiceAlwaysOn')]"
     }
  },
  "resources":[
     {
        "apiVersion":"[variables('apiVersion')]",
        "type":"config",
        "name":"appsettings",
        "dependsOn":[
           "[variables('WebAppName')]"
        ],
        "properties":{}
     },
      {
        "apiVersion":"[variables('siteApiVersion')]",
        "type": "config",                  
        "name": "slotconfignames",
        "dependsOn": [
          "[concat('Microsoft.Web/sites/', variables('WebAppName'))]"
        ],
        "properties": {
          "appSettingNames": [ "WEBJOBS_DISABLE_SCHEDULE" ]
        }
      },
      {
        "apiVersion":"[variables('siteApiVersion')]",
        "condition":"[parameters('stagingSlotEnabled')]",
        "name":"[parameters('stagingSlotName')]",
        "type":"slots",
        "tags":{
           "displayName":"[concat(variables('WebAppName'), ' ', parameters('stagingSlotName'))]"
        },
        "location":"[variables('location')]",
        "dependsOn":[
           "[resourceId('Microsoft.Web/Sites', variables('WebAppName'))]"
        ],
        "properties":{},
        "resources":[
          {
            "apiVersion":"[variables('apiVersion')]",
            "type":"config",                  
            "name":"appsettings",
            "dependsOn":[
              "[resourceId('Microsoft.Web/Sites/Slots', variables('WebAppName'), parameters('stagingSlotName'))]"
            ],
            "properties":{
              "WEBJOBS_DISABLE_SCHEDULE" : "1"
            }
          }
        ]
     }
  ]
}

]

于 2018-08-16T08:43:12.633 回答
0

在挠头一千次后,我找到了解决方案!

  1. 对于生产槽(默认槽),您需要添加资源(站点的子资源),如下所示

    "resources":[ { "name":"appsettings", "type":"config", "apiVersion":"2018-11-01", "dependsOn":[ "[concat('Microsoft.Web/sites/', parameters('webAppName'))]" ], "tags":{ "displayName":"uisettings" }, "properties":{ "AppSettingKey1":"myvalue", "WEBSITE_LOCAL_CACHE_OPTION":"Always", "WEBSITE_LOCAL_CACHE_SIZEINMB":"2000" } }, { "name":"connectionstrings", "type":"config", "location":"[parameters('location')]", "tags":{ "displayName":"uisettings" }, "apiVersion":"2018-11-01", "dependsOn":[ "[resourceId('Microsoft.Web/sites',parameters('webAppName'))]" ], "properties":{ "ConnString2":{ "value":"[parameters('connectionstring')]", "type":"SQLServer" } } }, { "apiVersion":"2018-11-01", "name":"slotconfignames", "type":"config", "dependsOn":[ "[concat('Microsoft.Web/sites/', parameters('webAppName'))]" ], "properties":{ "appSettingNames":[ "WEBSITE_LOCAL_CACHE_OPTION", "WEBSITE_LOCAL_CACHE_SIZEINMB" ], "connectionStringNames":[ "ConnString2" ] } } ]

  2. 对于不需要“ slotconfignames ”资源的插槽, slotconfignames 仅适用于默认(生产插槽)PFA 插槽的工作代码

    "resources":[ { "name":"appsettings", "type":"config", "apiVersion":"2018-11-01", "dependsOn":[ "[resourceId('Microsoft.Web/sites/slots',parameters('webAppName'),'Staging')]" ], "tags":{ "displayName":"uisettings" }, "properties":{ "AppSettingKey1":"myvalue", "WEBSITE_LOCAL_CACHE_OPTION":"Always", "WEBSITE_LOCAL_CACHE_SIZEINMB":"2000" } }, { "name":"connectionstrings", "type":"config", "location":"[parameters('location')]", "tags":{ "displayName":"uisettings" }, "apiVersion":"2018-11-01", "dependsOn":[ "[resourceId('Microsoft.Web/sites/slots',parameters('webAppName'),'Staging')]" ], "properties":{ "ConnString2":{ "value":"[parameters('connectionstring')]", "type":"SQLServer" } } } ],

于 2020-01-09T05:37:45.667 回答