如何在 Azure Arm 模板中使用粘性暂存槽 [英] How to use sticky staging slots in Azure Arm Templates

查看:21
本文介绍了如何在 Azure Arm 模板中使用粘性暂存槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不覆盖现有应用设置的情况下使用 ARM 模板将粘性设置部署到 Azure Web 应用中的生产应用槽?

How can you deploy sticky settings to a production app slot in azure web apps using ARM templates without overwriting the existing app settings?

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

I'm using Azure ARM templates to deploy my environment and code releases. The environment has both Staging and Production slots. Part of the deployment is deploying AppSettings. We deploy to Staging, test, then swap to prod.

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

This system has been working well until now, when I need to deploy a sticky AppSetting to prod. Normally, the deployments are incremental, but when I try to create a sticky setting for production, all of the other settings get wiped out.

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

I'm using slotconfignames to specify the sticky variables in the prod slot

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

我尝试为 prod appsettings 和 stage appsettings 创建单独的资源 - 当我这样做时,prod slot appsettings 将被完全覆盖.这是意料之中的:

I've tried creating separate resources for the prod appsettings and the stage appsettings - when I do, the prod slot appsettings are completely overwritten. 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"
      }
    },

如果我将这些设置作为阶段槽设置的一部分进行,那么它们不会在 prod 上设置,而是在阶段槽上设置为粘性.

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.

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

推荐答案

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

when I need to deploy a sticky AppSetting to prod. Normally, the deployments are incremental, but when I try to create a sticky setting for production, all of the other settings get wiped out.

根据我的测试,如您所说,您的 ARM 模板中未定义的 App 设置将被清除.当您 指定粘滞槽设置.

Based on my test, as you said, the App settings that are not defined in your ARM template will be wiped out. Please make sure you include all App settings in your ARM template when you specify sticky slot settings.

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

这篇关于如何在 Azure Arm 模板中使用粘性暂存槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆