通过 ARM msdeploy/zipdeploy 部署到多个子应用程序/虚拟应用程序部署到 Azure Web 应用

Deploying to an Azure Web App via ARM msdeploy/zipdeploy to multiple Sub-Applications / Virtual-Applications

提问人:Frank Leao 提问时间:11/15/2023 最后编辑:Frank Leao 更新时间:11/18/2023 访问量:105

问:

我希望你能帮助我解决以下情况。

我们希望在某些子应用程序/虚拟应用程序上部署 Azure Web 应用。但是,我们在互联网上研究的内容对于所需的技术并不是很精确,但我怀疑使用 ARM 无法完成。

如果有人有引导我们实现目标的信息,或者使用此技术是不可能的,或者它是 Azure 错误,我们不胜感激。

我们尝试将“IIS Web 应用程序名称”设置为

  1. “[参数('appName')]/subapp1”
  2. “/subapp1”
  3. “子应用1”
  4. “默认网站/subapp1”

我们使用了扩展:

  1. MSDeploy,
  2. addOnPackages 和
  3. Zip部署

结果始终是一样的,文件保留在 Web 应用程序的根目录上。

这是我们使用的 ARM 模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "metadata": {
                "description": "Location of resources"
            },
            "defaultValue": "[resourceGroup().location]"
        },
        "_artifactsLocation": {
            "type": "string",
            "metadata": {
                "description": "The base URI where artifacts required by this template are located including a trailing '/'"
            },
            "defaultValue": "[deployment().properties.templateLink.uri]"
        },
        "_artifactsLocationSasToken": {
            "type": "securestring",
            "metadata": {
                "description": "The sasToken required to access _artifactsLocation.  When the template is deployed using the accompanying scripts, a sasToken will be automatically generated. Use the defaultValue if the staging location is not secured."
            },
            "defaultValue": ""
        },
        "appName": {
            "type": "string",
            "metadata": {
                "description": "App Name"
            },
            "defaultValue": "testapp123"
        }
    },
    "variables": {
        "existingPlanAppServiceName": "[concat('PlanAppService-',uniqueString(resourceGroup().id))]"
    },
    "resources": [
        {
            "apiVersion": "2022-03-01",
            "name": "[variables('existingPlanAppServiceName')]",
            "type": "Microsoft.Web/serverfarms",
            "location": "[parameters('location')]",
            "kind": "",
            "tags": {},
            "dependsOn": [],
            "properties": {
                "name": "[variables('existingPlanAppServiceName')]",
                "workerSize": "18",
                "workerSizeId": "18",
                "numberOfWorkers": "1",
                "zoneRedundant": false
            },
            "sku": {
                "Tier": "Premium0V3",
                "Name": "P0V3"
            }
        },
        {
            "apiVersion": "2022-03-01",
            "name": "[parameters('appName')]",
            "type": "Microsoft.Web/sites",
            "location": "[parameters('location')]",
            "tags": {},
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', variables('existingPlanAppServiceName'))]"
            ],
            "properties": {
                "name": "[parameters('appName')]",
                "siteConfig": {
                    "metadata": [
                        {
                            "name": "CURRENT_STACK",
                            "value": "dotnet"
                        }
                    ],
                    "virtualApplications": [
                        {
                            "virtualPath": "/",
                            "physicalPath": "site\\wwwroot",
                            "preloadEnabled": false
                        },
                        {
                            "virtualPath": "/subapp1",
                            "physicalPath": "site\\wwwroot\\subapp1",
                            "preloadEnabled": true
                        }
                    ],
                    "phpVersion": "OFF",
                    "netFrameworkVersion": "v4.0",
                    "alwaysOn": true,
                    "ftpsState": "Disabled",
                    "use32BitWorkerProcess": false,
                    "http20Enabled": true,
                    "websiteTimeZone": "SA Pacific Standard Time"
                },
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('existingPlanAppServiceName'))]",
                "clientAffinityEnabled": false,
                "httpsOnly": true,
                "publicNetworkAccess": "Enabled"
            },
            "resources": [
                {
                    "type": "Microsoft.Web/sites/extensions",
                    "apiVersion": "2022-03-01",
                    "name": "[concat(parameters('appName'), '/MSDeploy')]",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/sites', parameters('appName'))]"
                    ],
                    "properties": {
                        "packageUri": "[uri(concat(parameters('_artifactsLocation'),'filesApp.zip'),parameters('_artifactsLocationSasToken'))]",
                        "dbType": "None",
                        "connectionString": "",
                        "appOffline": true,
                        "setParameters": {
                            "IIS Web Application Name": "[concat(parameters('appName'),'/subapp1')]"
                        }
                    }
                }
            ]
        }
    ]
}

非常感谢您的帮助。

azure-web-app-service azure-resource-manager webdeploy zipdeploy

评论

0赞 Jahnavi 11/15/2023
根据要求,您的代码对我来说看起来不错。您可以尝试直接在资源下的 中设置虚拟应用程序,而不是依赖于扩展的参数。你试过那样吗?@Frank LeaoMSDeploy"IIS Web Application Name"Microsoft.Web/sitessiteconfig
0赞 Frank Leao 11/15/2023
嗨,@Jahnavi,是的,在我上传的示例代码中,siteConfig 下有 virtualApplications 赋值,它们是在 Web 应用程序中正确创建的。但是,MSDeploy 不会部署在子应用程序的路径上,它始终将文件托管在根目录上。事实上,无论分配给“IIS Web 应用程序名称”的值如何,MSDeploy 始终将文件托管在根站点中,并且我们需要它位于子应用程序的路径上。您的代码是将文件部署到虚拟应用程序的路径,还是它们也保留在根目录中?你能和我分享一下吗?
0赞 Jahnavi 11/16/2023
理解。但在这里,默认情况下,它的功能是部署到单个应用程序,它不理解子应用程序的概念。若要部署到根以外的路径中,需要在站点扩展资源下添加属性。@Frank LeaoMSDeploycustom deployment script
0赞 Frank Leao 11/16/2023
准备好!,这就是我想知道的,非常感谢你@Jahnavi

答:

0赞 Jahnavi 11/15/2023 #1

根据您的要求,您的代码对我来说看起来不错。该问题可能是由于部署资源时造成的。"IIS Web Application Name"

您可以尝试直接在资源中的 下设置虚拟应用程序路径,而不是依赖于扩展的参数。MSDeploy"IIS Web Application Name"Microsoft.Web/sitessiteconfig

"siteConfig":  { 
  "virtualApplications":  [  
      { 
   "virtualPath":  "/add your requirement of virtual path here", 
   "physicalPath":  "site\\wwwroot\\xxxappexample", 
    "preloadEnabled":  true
      } 
   ], 
  }

因此,在数组中显式定义虚拟应用程序可确保在部署后将文件部署到正确的位置。"virtualApplications"

检查了上述所有内容后,我在我的环境中尝试了您的代码,并且部署成功,如下所示。

enter image description here

0赞 Frank Leao 11/18/2023 #2

默认情况下,MSDeploy 的功能是部署到单个应用程序,它不了解子应用程序的概念。若要部署到根以外的路径中,需要在站点扩展资源下添加属性。@Jahvani的回答,谢谢!custom deployment script