通过ARM / msdeploy部署到Azure Web App而不删除现有文件

时间:2017-08-24 18:33:08

标签: azure azure-web-sites msdeploy azure-resource-manager

使用常规msdeploy(也称为WebDeploy,用于Visual Studio或VSTS发布)部署到Azure Web App(也称为Azure App Service)时,您可以选择删除目标位置的现有文件

但是在使用ARM extensions/msdeploy提供程序时(例如通过ARM模板),默认情况下始终会删除现有文件。有没有办法覆盖这个而不是吹掉现有的文件?

1 个答案:

答案 0 :(得分:5)

Azure Web App支持DoNotDeleteRule的方式是通过addOnPackages架构元素。

addOnPackages 隐式使用DoNotDelete规则。因此,如果要在不删除现有站点中的文件的情况下应用程序包,请在addOnPackages数组中指定它,然后不要在外部MSDeploy对象中定义任何内容。 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"
    }
}

addOnPackages 还允许在单个MSDeploy ARM模板中使用多个包;外部将删除现有站点的文件,addOnPackages是附加的,不会删除外部包。 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"
    }
}