【问题标题】:How to use sticky staging slots in Azure Arm Templates如何在 Azure Arm 模板中使用粘性暂存槽
【发布时间】:2018-01-03 17:58:15
【问题描述】:

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

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

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

我正在使用 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" ]
      }
    }

我尝试为 prod appsettings 和 stage appsettings 创建单独的资源 - 当我这样做时,prod slot 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"
      }
    },

如果我将这些设置作为阶段槽设置的一部分进行,那么它们不会在 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"
    }
  },

【问题讨论】:

    标签: azure deployment azure-web-app-service azure-resource-manager


    【解决方案1】:

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

    根据我的测试,如您所说,您的 ARM 模板中未定义的 App 设置将被清除。当您specify sticky slot settings 时,请确保在您的 ARM 模板中包含所有 App 设置。

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

    【讨论】:

    • 这个“你的ARM模板中没有定义的App设置将被清除”,你的意思是你需要在两个槽(源槽和目标槽)中定义所有的appsettings,对吧?你不能只添加粘性设置,然后重新部署 ARM,那么只有粘性设置会被重写,但所有其他设置都会被擦除,对吗?
    • 但是在这里拥有所有 AppSettings,这是否意味着您现在在运行此 ARM 时将更新的 appsettings 部署到生产槽,而不是在您希望它的交换期间?
    • 在生产槽上部署设置不会导致重启吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多