简体   繁体   English

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

[英]How to use sticky staging slots in Azure Arm Templates

How can you deploy sticky settings to a production app slot in azure web apps using ARM templates without overwriting the existing app settings? 如何使用ARM模板将粘性设置部署到azure Web应用程序中的生产应用程序插槽,而不会覆盖现有的应用程序设置?

I'm using Azure ARM templates to deploy my environment and code releases. 我正在使用Azure ARM模板来部署我的环境和代码版本。 The environment has both Staging and Production slots. 环境具有暂存和生产插槽。 Part of the deployment is deploying AppSettings. 部署部分是部署AppSettings。 We deploy to Staging, test, then swap to prod. 我们部署到Staging,测试,然后交换到prod。

This system has been working well until now, when I need to deploy a sticky AppSetting to prod. 这个系统一直运行良好,直到现在,我需要部署一个粘性的AppSetting来生产。 Normally, the deployments are incremental, but when I try to create a sticky setting for production, all of the other settings get wiped out. 通常,部署是增量的,但是当我尝试为生产创建粘性设置时,所有其他设置都会被删除。

I'm using slotconfignames to specify the sticky variables in the prod slot 我正在使用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" ]
      }
    }

I've tried creating separate resources for the prod appsettings and the stage appsettings - when I do, the prod slot appsettings are completely overwritten. 我已经尝试为prod appsettings和舞台appsettings创建单独的资源 - 当我这样做时,prod插槽appsettings被完全覆盖。 This is somewhat expected: 这有点预期:

 {
      "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"
      }
    },

If I make those same settings as part of the stage slot settings, then they aren't set on prod, but are set as sticky on the stage slot. 如果我将这些设置设置为舞台插槽设置的一部分,则它们不会在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"
    }
  },

when I need to deploy a sticky AppSetting to prod. 当我需要部署一个粘性的AppSetting来生产时。 Normally, the deployments are incremental, but when I try to create a sticky setting for production, all of the other settings get wiped out. 通常,部署是增量的,但是当我尝试为生产创建粘性设置时,所有其他设置都会被删除。

Based on my test, as you said, the App settings that are not defined in your ARM template will be wiped out. 根据我的测试,正如您所说,ARM模板中未定义的应用程序设置将被清除。 Please make sure you include all App settings in your ARM template when you specify sticky slot settings . 指定粘滞槽设置时,请确保在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" ]
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM