Deploying an Azure web application through ARM / msdeploy without deleting existing files

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

But when using the ARM provider extensions/msdeploy(for example, using the ARM template), existing files are always deleted by default. Is there a way to undo this and not tear down existing files?

+4
source share
1 answer

How Azure Web App supports the DoNotDeleteRule through the addOnPackages schema element.

addOnPackages use the DoNotDelete rule implicitly. So, if you want to apply the package without deleting the files on the existing site, you will specify it in the addOnPackages array, and then do not define anything in the external MSDeploy object. eg:.

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

addOnPackages also allows you to use multiple packages in one MSDeploy ARM template; External will delete files for the existing site, and addOnPackages are additive and will not delete the external package. eg:.

{
    "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"
    }
}
+4
source

Source: https://habr.com/ru/post/1684407/


All Articles