将AzureFunctions部署到同一ARM模板中新创建的AppService的问题

时间:2018-04-03 18:31:37

标签: azure-functions msdeploy arm-template

我正在使用ARM模板来部署azure函数。我的步骤如下

1)推臂模板到blob存储并获得SAS uri 2)将azure函数推送到blob存储并获取SAS uri 3)运行powershell命令New-AzureRmResourceGroup来创建我的新资源组 4)运行powershell命令New-AzureRmResourceGroupDeployment以通过ARM模板部署我的应用程序。

在我的Arm模板中,我使用MSDeploy的嵌套模板通过zip文件发送我的azure函数。

第一次部署将创建我的所有资源,但不会部署我的Azure功能。

如果我使用相同的arm模板通过相同的进程部署到我新创建的资源和资源组,我的部署将使用我的azure函数。我不确定这个过程是怎么回事,因为两个部署都认为是成功的。

这是我的天蓝色功能臂模板与MSDeploy

{
        "type": "Microsoft.Web/sites",
        "apiVersion": "2015-08-01",
        "name": "[variables('functionsName')]",
        "location": "[resourceGroup().location]",
        "kind": "functionapp",
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms',variables('hostPlanName'))]",
            "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]",
            "[resourceId('Microsoft.Insights/components', variables('appInsightsName'))]"
        ],
        "properties": {
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostPlanName'))]",
            "name": "[variables('functionsName')]"
        },
        "resources": [ 
            {
                "name": "MSDeploy",
                "type": "extensions",
                "location": "[resourceGroup().location]",
                "apiVersion": "2015-08-01",
                "dependsOn": [
                    "[concat('Microsoft.Web/sites/', variables('functionsName'))]"
                ],
                "properties": {
                    "packageUri": "[concat(parameters('_artifactsLocation'),  parameters('SampleFunctionAppPackageFolder'), '/', parameters('SampleFunctionAppPackageFileName'), parameters('_artifactsLocationSasToken'))]",
                }
            },
            {
                "apiVersion": "2016-03-01",
                "name": "appsettings",
                "type": "config",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/sites', variables('functionsName'))]",
                    "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]",
                    "[concat('Microsoft.Web/sites/', variables('functionsName'), '/Extensions/MSDeploy')]"
                ],
                "properties": {
                   ****  App settings removed *****
                }
            }
        ]
    }

1 个答案:

答案 0 :(得分:2)

事实证明,将appSettings放在不同的ARM模板中会导致此问题的azure函数在第一次运行时没有部署。将AppSettings移动到appFunction ARM模板,例如

"type": "Microsoft.Web/sites",
    "apiVersion": "2015-08-01",
    "name": "[variables('functionsName')]",
    "location": "[resourceGroup().location]",
    "kind": "functionapp",
    "identity": {
        "type": "SystemAssigned"
    },
    "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms',variables('hostPlanName'))]"
    ],
    "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostPlanName'))]",
        "name": "[variables('functionsName')]",
        "siteConfig": {
            "appSettings": [
                {
                    "name": "key1",
                    "value": "value1"
                }
            ]
        }
    }           
}

我试图避免这里解释的死锁问题https://blogs.msdn.microsoft.com/hosamshobak/2016/05/26/arm-template-msdeploy-race-condition-issue/

但是我们在这些步骤中看到了这个错误。在部署时我还没遇到这个死锁问题但是仍然可能,因为我不知道是否已经使用MSDeploy解决了死锁问题。