Версия среды выполнения функции Azure устанавливается равной ~ 1 при развертывании

#azure #azure-functions #azure-resource-manager #arm-template

#azure #azure-функции #azure-resource-manager #arm-шаблон

Вопрос:

У меня есть конвейер AzureDevOps, который развертывает функцию Azure, используя следующий шаблон ARM:

 {
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "functionAppCSName": {
            "type": "string"
        },
        "storageAccountName": {
            "type": "string"
        },
        "storageAccountType": {
            "type": "string",
            "defaultValue": "Standard_LRS",
            "metadata": {
                "description": "Geo-replication type of Storage account"
            },
            "allowedValues": [
                "Standard_LRS",
                "Standard_GRS",
                "Standard_ZRS",
                "Standard_RGRS"
            ]
        },
        "serverFarmsName": {
            "type": "string"
        },
        "appInsightsName": {
            "type": "string"
        },
        "appinsightResourceGroupName": {
            "type": "string"
        },
        "webURL": {
            "type": "string"
        },
        "vaultName": {
            "type": "string"
        },
        "sspVaultName": {
            "type": "string"
        },
        "marketplaceVaultName": {
            "type": "string"
        },
        "redisRgName": {
            "type": "string"
        },
        "redisName": {
            "type": "string"
        },
        "environment": {
            "type": "string"
        },
        "aadTenant": {
            "type": "string"
        },
        "aadClientId": {
            "type": "string"
        },
        "audience": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[parameters('storageAccountName')]",
            "location": "[parameters('location')]",
            "apiVersion": "2019-04-01",
            "sku": {
                "name": "[parameters('storageAccountType')]"
            },
            "kind": "StorageV2",
            "properties": {
            }
        },
        {
            "type": "Microsoft.Web/sites",
            "kind": "functionapp",
            "name": "[parameters('functionAppCSName')]",
            "apiVersion": "2016-08-01",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
            ],
            "identity": {
                "type": "SystemAssigned"
            },
            "tags": {
            },
            "properties": {
                "httpsOnly": true,
                "enabled": true,
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('serverFarmsName'))]",
                "reserved": false,
                "siteConfig": {
                    "AlwaysOn": true,
                    "ftpsState": "Disabled"
                },
                "clientAffinityEnabled": true,
                "clientCertEnabled": false,
                "hostNamesDisabled": false,
                "containerSize": 1536,
                "dailyMemoryTimeQuota": 0,
                "remoteDebuggingEnabled": false,
                "webSocketsEnabled": false
            },
            "resources": [
                {
                    "apiVersion": "2016-08-01",
                    "name": "appsettings",
                    "type": "config",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('functionAppCSName'))]"
                    ],
                    "properties": {
                        "SSPSYSTEM_KEYVAULT_URI": "[concat('https://',parameters('sspvaultname'),'.vault.azure.net')]",
                        "SSP_KEYVAULT_URI": "[concat('https://',parameters('vaultName'),'.vault.azure.net')]",
                        "MP_KEYVAULT_URI": "[concat('https://',parameters('marketplaceVaultName'),'.vault.azure.net')]",
                        "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(parameters('storageAccountName'),'2019-06-01').keys[0].value)]",
                        "AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(parameters('storageAccountName'),'2019-06-01').keys[0].value)]",
                        "FUNCTIONS_EXTENSION_VERSION": "~3",
                        "AzureWebJobsSecretStorageType": "Files",
                        "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(parameters('appinsightResourceGroupName'),'Microsoft.Insights/components', parameters('appInsightsName')), '2014-04-01').InstrumentationKey]",
                        "CacheConnectionString": "[concat(parameters('redisName'),'.redis.cache.windows.net,abortConnect=false,ssl=true,password=', listKeys(resourceId(parameters('redisRgName'),'Microsoft.Cache/Redis',parameters('redisName')), '2015-08-01').primaryKey)]",
                        "AssetCacheKey": "[parameters('environment')]"
                    }
                },
                {
                    "comments": "CORS allow origins *.",
                    "type": "Microsoft.Web/sites/config",
                    "name": "[concat(parameters('functionAppCSName'), '/web')]",
                    "apiVersion": "2016-08-01",
                    "properties": {
                        "cors": {
                            "allowedOrigins": [
                                "https://functions.azure.com",
                                "https://functions-staging.azure.com",
                                "https://functions-next.azure.com",
                                "[parameters('webURL')]",
                                "http://localhost:4200"
                            ]
                        }
                    },
                    "dependsOn": [
                        "[concat('Microsoft.Web/sites/', parameters('functionAppCSName'))]",
                        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
                    ]
                },
                {
                    "type": "config",
                    "name": "logs",
                    "apiVersion": "2016-08-01",
                    "location": "[parameters('location')]",
                    "dependsOn": [
                        "[concat('Microsoft.Web/sites/', parameters('functionAppCSName'))]",
                        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
                    ],
                    "properties": {
                        "remoteDebuggingEnabled": false,
                        "webSocketsEnabled": false,
                        "applicationLogs": {
                            "fileSystem": {
                                "level": "Off"
                            },
                            "azureTableStorage": {
                                "level": "Off",
                                "sasUrl": null
                            },
                            "azureBlobStorage": {
                                "level": "Verbose",
                                "sasUrl": "url",
                                "retentionInDays": 7
                            },
                            "httpLogs": {
                                "fileSystem": {
                                    "retentionInMb": 365,
                                    "retentionInDays": 365,
                                    "enabled": true
                                },
                                "azureBlobStorage": {
                                    "sasUrl": "url",
                                    "retentionInDays": 365,
                                    "enabled": true
                                }
                            },
                            "failedRequestsTracing": {
                                "enabled": true
                            },
                            "detailedErrorMessages": {
                                "enabled": true
                            }
                        }
                    }
                },
                {
                    "name": "[concat(parameters('functionAppCSName'), '/authsettings')]",
                    "apiVersion": "2016-08-01",
                    "type": "Microsoft.Web/sites/config",
                    "location": "[parameters('location')]",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/sites', parameters('functionAppCSName'))]"
                    ],
                    "properties": {
                        "enabled": true,
                        "tokenStoreEnabled": true,
                        "defaultProvider": "AzureActiveDirectory",
                        "clientId": "[parameters('aadClientId')]",
                        "issuer": "[concat('https://login.microsoftonline.com/', parameters('aadTenant'))]",
                        "allowedAudiences": [
                            "[parameters('audience')]"
                        ]
                    }
                }
            ]
        }
    ],
    "outputs": {
        "tenantID": {
            "type": "string",
            "value": "[reference(resourceId('Microsoft.Web/sites', parameters('functionAppCSName')),'2020-06-01', 'Full').identity.tenantId]"
        },
        "objectId": {
            "type": "string",
            "value": "[reference(resourceId('Microsoft.Web/sites', parameters('functionAppCSName')),'2020-06-01', 'Full').identity.principalId]"
        }
    }
}
  

Как вы можете видеть, я устанавливаю версию среды выполнения приложения-функции, выполняя следующие действия:

 ...
{
                    "apiVersion": "2016-08-01",
                    "name": "appsettings",
                    "type": "config",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('functionAppCSName'))]"
                    ],
                    "properties": {
                        "SSPSYSTEM_KEYVAULT_URI": "[concat('https://',parameters('sspvaultname'),'.vault.azure.net')]",
                        "SSP_KEYVAULT_URI": "[concat('https://',parameters('vaultName'),'.vault.azure.net')]",
                        "MP_KEYVAULT_URI": "[concat('https://',parameters('marketplaceVaultName'),'.vault.azure.net')]",
                        "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(parameters('storageAccountName'),'2019-06-01').keys[0].value)]",
                        "AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(parameters('storageAccountName'),'2019-06-01').keys[0].value)]",
                        "FUNCTIONS_EXTENSION_VERSION": "~3",
                        "AzureWebJobsSecretStorageType": "Files",
                        "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(parameters('appinsightResourceGroupName'),'Microsoft.Insights/components', parameters('appInsightsName')), '2014-04-01').InstrumentationKey]",
                        "CacheConnectionString": "[concat(parameters('redisName'),'.redis.cache.windows.net,abortConnect=false,ssl=true,password=', listKeys(resourceId(parameters('redisRgName'),'Microsoft.Cache/Redis',parameters('redisName')), '2015-08-01').primaryKey)]",
                        "AssetCacheKey": "[parameters('environment')]"
                    }
                }
...

  

Проблема в том, что при развертывании функции версия среды выполнения всегда устанавливается на 1 ~, и единственный способ исправить это — удалить приложение функции и повторно развернуть снова или выполнить повторное развертывание в конвейере снова и снова, пока оно не станет ~ 3.

Это действительно расстраивает нас, поскольку мы не можем обеспечить надлежащее или плавное развертывание.

Есть ли что-то, чего мне не хватает с точки зрения шаблона ARM?

Ответ №1:

Попробуйте изменить версию API на последнюю. Это должно быть сделано на всех создаваемых ресурсах /site.

 {
                    "apiVersion": "2020-06-01",
                    "name": "appsettings",
                    "type": "config",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('functionAppCSName'))]"
                    ],
  

Вы всегда можете просмотреть последние версии в документах Microsoft

Комментарии:

1. Мы уже пытались обновить все версии API, которые используют ресурсы, и все еще сталкиваемся с проблемой. Это в значительной степени ситуация попадания или промаха. :/