Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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.

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.

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

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

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"
    }
  },
like image 900
blackSphere Avatar asked Jul 27 '17 20:07

blackSphere


People also ask

What is staging slot in Azure?

You can validate app changes in a staging deployment slot before swapping it with the production slot. Deploying an app to a slot first and swapping it into production makes sure that all instances of the slot are warmed up before being swapped into production. This eliminates downtime when you deploy your app.

What does deployment slot setting mean?

Deployment Slot Setting With this setting in place, database connection strings are not swapped when the slots are swapped. So staging slot will always point to the staging database and production slot will always point to the production database.


1 Answers

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.

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" ]
  }
}
like image 56
Fei Han Avatar answered Sep 21 '22 12:09

Fei Han