Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying to an Azure Web App via ARM/msdeploy without deleting existing files

When deploying to an Azure Web App (aka Azure App Service) using regular msdeploy (a.k.a WebDeploy, used for Visual Studio or VSTS publishing), you can choose to not delete existing files at the destination.

But when using the ARM extensions/msdeploy provider (e.g. via an ARM template), existing files are always deleted by default. Is there a way to override this and not blow away existing files?

like image 356
David Ebbo Avatar asked Aug 24 '17 18:08

David Ebbo


1 Answers

The way Azure Web App supports the DoNotDeleteRule is via the addOnPackages schema element.

addOnPackages use the DoNotDelete rule implicitly. So, if you want to apply a package without deleting files in the existing site, you specify it in the addOnPackages array, and then don't define anything in the outer MSDeploy object. e.g.:

{
    "properties": {
        "parameters": {
            "appName": {
                "value": "mysite"
            },
            "location":{
                "value": "USAAnywhere"
            }
        },
        "template": {
            "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0-r188+188.764a8a7798ecc6ebb752343c6f8e6be2903ba711",
            "parameters": {
                "appName": {
                    "type": "string"
                },
                "location": {
                    "type": "string"
                }
            },
            "resources": [
                {
                    "apiVersion": "2016-08-01",
                    "name": "[parameters('appName')]",
                    "location": "[parameters('location')]",
                    "type": "Microsoft.Web/sites",
                    "resources": [
                        {
                            "apiVersion": "2016-08-01",
                            "name": "MSDeploy",
                            "type": "Extensions",
                            "dependsOn": [
                                "[concat('Microsoft.Web/Sites/', parameters('appName'))]"
                            ],
                            "properties": {
                                "addOnPackages" : [
                                    {
                                        "packageUri": "https://mystorageblob.blob.core.windows.net/package/my_webdeploy_package.zip",
                                        "AppOffline": true,
                                        "setParameters": {
                                            "IIS Web Application Name": "[parameters('appName')]",
                                         }
                                    }
                                ]
                            }
                        }
                    ],
                    "properties" : {}
                }
            ]
        },
        "mode": "Incremental"
    }
}

The addOnPackages also allows multiple packages in a single MSDeploy ARM template; The outer one will delete the files for the existing site, and the addOnPackages are additive and will not delete the outer package. e.g.:

{
    "properties": {
        "parameters": {
            "appName": {
                "value": "mysite"
            },
            "location":{
                "value": "USAAnywhere"
            }
        },
        "template": {
            "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0-r188+188.764a8a7798ecc6ebb752343c6f8e6be2903ba711",
            "parameters": {
                "appName": {
                    "type": "string"
                },
                "location": {
                    "type": "string"
                }
            },
            "resources": [
                {
                    "apiVersion": "2016-08-01",
                    "name": "[parameters('appName')]",
                    "location": "[parameters('location')]",
                    "type": "Microsoft.Web/sites",
                    "resources": [
                        {
                            "apiVersion": "2016-08-01",
                            "name": "MSDeploy",
                            "type": "Extensions",
                            "dependsOn": [
                                "[concat('Microsoft.Web/Sites/', parameters('appName'))]"
                            ],
                            "properties": {
                                "packageUri": "https://mystorageblob.blob.core.windows.net/package/my_webdeploy_package.zip",
                                "dbType": "None",
                                "connectionString": "",
                                "AppOffline": true,
                                "SkipAppData": true,
                                "setParameters": {
                                    "IIS Web Application Name": "[parameters('appName')]"
                                },
                                "addOnPackages" : [
                                    {
                                        "packageUri": "https://mystorageblob.blob.core.windows.net/package/my_first_add_on_package.zip",
                                        "AppOffline": true,
                                        "setParameters": {
                                            "IIS Web Application Name": "[parameters('appName')]",
                                         }
                                    },
                                    {
                                        "packageUri": "https://mystorageblob.blob.core.windows.net/package/my_second_add_on_package.zip",
                                        "setParameters": {
                                            "IIS Web Application Name": "[parameters('appName')]",
                                        }
                                    }
                                ]
                            }
                        }
                    ],
                    "properties" : {}
                }
            ]
        },
        "mode": "Incremental"
    }
}
like image 108
DropPhone Avatar answered Oct 18 '22 12:10

DropPhone