如何在Azure Arm模板中使用粘性临时插槽

bla*_*ere 5 deployment azure azure-web-sites azure-resource-manager

如何使用ARM模板将粘性设置部署到azure Web应用程序中的生产应用程序插槽,而不会覆盖现有的应用程序设置?

我正在使用Azure ARM模板来部署我的环境和代码版本.环境具有暂存和生产插槽.部署部分是部署AppSettings.我们部署到Staging,测试,然后交换到prod.

这个系统一直运行良好,直到现在,我需要部署一个粘性的AppSetting来生产.通常,部署是增量的,但是当我尝试为生产创建粘性设置时,所有其他设置都会被删除.

我正在使用slotconfignames来指定prod槽中的粘性变量

{
      "apiVersion": "2015-08-01",
      "name": "slotconfignames",
      "type": "config",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
      ],
      "properties": {
        "appSettingNames": [ "WEBSITE_LOCAL_CACHE_OPTION", "WEBSITE_LOCAL_CACHE_SIZEINMB" ]
      }
    }
Run Code Online (Sandbox Code Playgroud)

我已经尝试为prod appsettings和舞台appsettings创建单独的资源 - 当我这样做时,prod插槽appsettings被完全覆盖.这有点预期:

 {
      "apiVersion": "2015-08-01",
      "type": "config",
      "name": "appsettings",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites/', variables('webSiteName'))]"
      ],

      "properties": {
        "WEBSITE_LOCAL_CACHE_OPTION": "Always",
        "WEBSITE_LOCAL_CACHE_SIZEINMB": "2000"
      }
    },
Run Code Online (Sandbox Code Playgroud)

如果我将这些设置设置为舞台插槽设置的一部分,则它们不会在prod上设置,但在舞台插槽上设置为粘性.

{
    "name": "appsettings",
    "type": "config",
    "apiVersion": "2015-08-01",
    "dependsOn": [
      "[variables('stagingSlotName')]",
      //"[concat('Microsoft.Web/sites/', variables('webSiteName'))]",
      "MSDeploy",
      "[concat('Microsoft.Resources/deployments/', 'AppStorage')]"
    ],
    "tags": {
      "displayName": "uisettings",
      "environment": "[parameters('environmentName')]",
      "serviceGroup": "[variables('serviceGroupName')]"
    },
    "properties": {
      ...othersettingshere...         
      "WEBSITE_LOCAL_CACHE_OPTION": "Always",
      "WEBSITE_LOCAL_CACHE_SIZEINMB": "2000"
    }
  },
Run Code Online (Sandbox Code Playgroud)

Fei*_*Han 2

当我需要将粘性 AppSetting 部署到产品时。通常,部署是增量的,但是当我尝试为生产创建粘性设置时,所有其他设置都会被清除。

根据我的测试,正如您所说,ARM模板中未定义的应用程序设置将被清除。当您指定粘性插槽设置时,请确保在 ARM 模板中包含所有应用程序设置。

{
  "name": "appsettings",
  "type": "config",
  "apiVersion": "2015-08-01",
  "dependsOn": [
    "[concat('Microsoft.Web/sites/', variables('webSiteName'))]"
  ],
  "tags": {
    "displayName": "uisettings"
  },
  "properties": {
    "AppSettingKey1": "myvalue",
    //your other appsettings
    "WEBSITE_LOCAL_CACHE_OPTION": "Always",
    "WEBSITE_LOCAL_CACHE_SIZEINMB": "2000"
  }
},
{
  "apiVersion": "2015-08-01",
  "name": "slotconfignames",
  "type": "config",
  "dependsOn": [
    "[concat('Microsoft.Web/sites/', variables('webSiteName'))]"
  ],
  "properties": {
    "appSettingNames": [ "WEBSITE_LOCAL_CACHE_OPTION", "WEBSITE_LOCAL_CACHE_SIZEINMB" ]
  }
}
Run Code Online (Sandbox Code Playgroud)