Part 5: Deployment Slots

Sitecore 9 in Azure Paas for Dummies

Preface

In this final post of the Sitecore 9 in Azure Paas series we are going to customize the ARM templates to support deployment slots.

Creating deployment slots in Azure

In this tutorial, we will add the deployment slots manually to our Azure setup. So we will not modify the templates to include in the provisioning of our infrastructure through the ARM templates.

The ARM templates will only support deployment to these new “staging slots”.

  1. Before adding slots you need to make sure, the hosting plan of your app service is minimum in the “standard” tier. Basic tier will not cover this. To upgrade the hosting, go to “Scale up” –> Production, select one of the standard tiers.
  2. Next, go to deployment slots on the App Service and add a new slot

Creating ARM templates

In application.json in the nested subfolder, a typical resource would look like this.

{
  "name": "[concat(variables('cdWebAppNameTidy'), '/', 'MSDeploy')]",
  "type": "Microsoft.Web/sites/extensions",
  "location": "[parameters('location')]",
  "apiVersion": "[variables('webApiVersion')]",
  "dependsOn": [ "[concat('Microsoft.Web/sites/', variables('cmWebAppNameTidy'), '/Extensions/MSDeploy')]" ],
  "properties": {
	"packageUri": "[parameters('cdMsDeployPackageUrl')]",
	"dbType": "SQL",
	"connectionString": "[concat('Data Source=tcp:', variables('sqlServerFqdnTidy'), ',1433;Initial Catalog=master;User Id=', parameters('sqlServerLogin'), ';Password=', parameters('sqlServerPassword'), ';')]",
	"setParameters": {
	  "Application Path": "[variables('cdWebAppNameTidy')]",
	},
	"addOnPackages": [
	  {
		"packageUri": "[parameters('disablePrefetchCachingMsDeployPackageUrl')]",
		"setParameters": {
		  "Application Path": "[variables('cdWebAppNameTidy')]"
		}
	  }         
	]
  }
}

When using staging slots we need to wrap this like

{
  "type": "Microsoft.Web/sites",
  "name": "[variables('cdWebAppNameTidy')]",
  "apiVersion": "[variables('webApiVersion')]",
  "properties": {},
  "location": "[parameters('location')]",
  "resources": [
	{
	  "type": "slots",
	  "name": "staging",
	  "apiVersion": "[variables('webApiVersion')]",
	  "properties": {},
	  "location": "[parameters('location')]",
	  "dependsOn": [
		"[resourceId('Microsoft.Web/sites', variables('cdWebAppNameTidy'))]"
	  ],
	  "resources": [
		{
		  "name": "MSDeploy",
		  "type": "extensions",
		  "location": "[parameters('location')]",
		  "apiVersion": "[variables('webApiVersion')]",
		  "dependsOn": [
			"[resourceId('Microsoft.Web/sites/slots', variables('cdWebAppNameTidy'), 'staging')]",
			"[concat('Microsoft.Web/sites/', variables('cmWebAppNameTidy'), '/Extensions/MSDeploy')]" 
		  ],
		  "properties": {
			"packageUri": "[parameters('cdMsDeployPackageUrl')]",
			"dbType": "SQL",
			"connectionString": "[concat('Data Source=tcp:', variables('sqlServerFqdnTidy'), ',1433;Initial Catalog=master;User Id=', parameters('sqlServerLogin'), ';Password=', parameters('sqlServerPassword'), ';')]",
			"setParameters": {
			  "Application Path": "[variables('cdWebAppNameTidy')]",
			  ...
			},
			"addOnPackages": [
			  {
				"packageUri": "[parameters('disablePrefetchCachingMsDeployPackageUrl')]",
				"setParameters": {
				  "Application Path": "[variables('cdWebAppNameTidy')]"
				}
			  }         
			]
		  }
		}
	  ]
	}
  ]
}

Basically, we access the main app service, go to its “staging” slot resource and on this resource we execute the MSDeploy extention.

Important here, is to take a look at the “dependsOn” properties. We need to add a dependency to the staging slot.

Deploy AppSettings

The appsettings need to be deployed to the staging slot as well.

For this, we also move the appsettings block into the staging wrapper.

{
  "name": "appsettings",
  "type": "config",
  "apiVersion": "[variables('webApiVersion')]",
  "properties": {
	"WEBSITE_LOAD_CERTIFICATES": "[parameters('authCertificateThumbprint')]",
	"WEBSITE_DYNAMIC_CACHE": 0
  },
  "dependsOn": [
	"[resourceId('Microsoft.Web/sites/slots', variables('cdWebAppNameTidy'), 'staging')]",
	"[concat('Microsoft.Web/sites/', variables('cdWebAppNameTidy'), '/slots/staging/Extensions/MSDeploy')]"
  ]
}

Also here, have a look at the dependsOn that needs to be addapted.

Download

The full ARM template supporting deployment to CD in a staging slot can be found here:

application-cmcd-slots

In this ARM template, CM is still deployed to the main production slot, but CD is deployed into a staging slot.

The same changes could be applied to deploy CM to a staging slot as well.

What’s Next?

This post concludes the Sitecore 9 in Azure Paas for Dummies series.

Want more? Please read my blog posts on:

Leave a Reply