Azure Functions ARM模板重新部署会删除我发布的函数

时间:2018-10-03 08:55:54

标签: azure-devops azure-functions azure-resource-manager azure-functions-runtime azure-functions-core-tools

我有一个由ARM模板使用Azure DevOps管道部署的Azure Functions(2.0)实例。我有另一个管道,通过zip部署将功能应用程序部署到实例。这几乎可以完美地工作,但是,如果我将功能Infrastructure部署为Code,然后部署应用程序,然后将Infrastructure部署为Code,则我的功能应用程序将被删除,所有功能都将消失。我正在使用增量部署,所以我想知道为什么这样做。关于它为什么会这样或如何进行故障排除的任何想法?

我已在下面复制了资源组部署脚本和ARM模板。

New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
                                   -ResourceGroupName $ResourceGroupName `
                                   -TemplateFile $TemplateFile `
                                   -TemplateParameterFile $TemplateParametersFile `
                                   -Mode Incremental `
                                   @OptionalParameters `
                                   -Force -Verbose `
                                   -AdminsGroup $AdminsGroup `
                                   -AdminsGroupObjectId $AdminsGroupObjectId `
                                   -ErrorVariable ErrorMessages

ARM模板

  {
  "type": "Microsoft.Web/serverfarms",
  "sku": {
    "name": "Y1",
    "tier": "Dynamic",
    "size": "Y1",
    "family": "Y",
    "capacity": 0
  },
  "kind": "app",
  "apiVersion": "2016-09-01",
  "name": "[variables('FunctionPlanNameMyStuff')]",
  "location": "[resourceGroup().location]",

  "properties": {
    "name": "[variables('FunctionPlanNameMyStuff')]",
    "perSiteScaling": false,
    "reserved": false,
    "targetWorkerCount": 0,
    "targetWorkerSizeId": 0
  }
},
{
  "comments": "MyStuff Functions Site",
  "type": "Microsoft.Web/sites",
  "kind": "functionapp",
  "name": "[variables('FunctionSiteNameMyStuff')]",
  "apiVersion": "2016-08-01",
  "location": "[resourceGroup().location]",
  "identity": {
    "type": "SystemAssigned"
  },
  "scale": null,
  "properties": {
    "enabled": true,
    "hostNameSslStates": [
      {
        "name": "[concat(variables('FunctionSiteNameMyStuff'),'.azurewebsites.net')]",
        "sslState": "Disabled",
        "virtualIP": null,
        "thumbprint": null,
        "toUpdate": null,
        "hostType": "Standard"
      },
      {
        "name": "[concat(variables('FunctionSiteNameMyStuff'),'.scm.azurewebsites.net')]",
        "sslState": "Disabled",
        "virtualIP": null,
        "thumbprint": null,
        "toUpdate": null,
        "hostType": "Repository"
      }
    ],
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('FunctionPlanNameMyStuff'))]",
    "reserved": false,
    "siteConfig": null,
    "scmSiteAlsoStopped": false,
    "hostingEnvironmentProfile": null,
    "clientAffinityEnabled": false,
    "clientCertEnabled": false,
    "hostNamesDisabled": false,
    "containerSize": 1536,
    "dailyMemoryTimeQuota": 0,
    "cloningInfo": null
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "appsettings",
      "type": "config",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', variables('FunctionSiteNameMyStuff'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('FunctionStorageAccountMyStuff'))]"
      ],
      "properties": {
        "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('FunctionStorageAccountMyStuff'), ';AccountKey=', listKeys(variables('FunctionStorageResourceIdMyStuff'), '2017-10-01').keys[0].value)]",
        "AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('FunctionStorageAccountMyStuff'), ';AccountKey=', listKeys(variables('FunctionStorageResourceIdMyStuff'), '2017-10-01').keys[0].value)]",
        "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('FunctionStorageAccountMyStuff'), ';AccountKey=', listKeys(variables('FunctionStorageResourceIdMyStuff'),'2015-05-01-preview').key1)]",
        "WEBSITE_CONTENTSHARE": "[toLower(variables('FunctionSiteNameMyStuff'))]",
        "FUNCTIONS_EXTENSION_VERSION": "~2",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "FUNCTION_APP_EDIT_MODE": "readwrite",
        "KeyVaultUrl": "[concat('https://', variables('KeyVaultName'), '.vault.azure.net/')]",
        "DeveloperMode": false
      }
    }
  ],
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('FunctionPlanNameMyStuff'))]",
    "[resourceId('Microsoft.Storage/storageAccounts', variables('FunctionStorageAccountMyStuff'))]"
  ]
},
{
  "comments": "Functions web site config",
  "type": "Microsoft.Web/sites/config",
  "name": "[concat(variables('FunctionSiteNameMyStuff'), '/', 'web')]",
  "apiVersion": "2016-08-01",
  "location": "[resourceGroup().location]",
  "tags": {
  },
  "scale": null,
  "properties": {
    "numberOfWorkers": 1,
    "defaultDocuments": [
      "Default.htm",
      "Default.html",
      "Default.asp",
      "index.htm",
      "index.html",
      "iisstart.htm",
      "default.aspx",
      "index.php",
      "hostingstart.html"
    ],
    "netFrameworkVersion": "v4.0",
    "phpVersion": "5.6",
    "pythonVersion": "",
    "nodeVersion": "",
    "linuxFxVersion": "",
    "requestTracingEnabled": false,
    "remoteDebuggingEnabled": false,
    "remoteDebuggingVersion": null,
    "httpLoggingEnabled": false,
    "logsDirectorySizeLimit": 35,
    "detailedErrorLoggingEnabled": false,
    "publishingUsername": "[concat('$', variables('FunctionSiteNameMyStuff'), 'pubuser')]",
    "publishingPassword": "[concat(variables('FnAppPublishingPasswordMyStuff'), uniqueString(resourceGroup().id))]",
    "appSettings": null,
    "metadata": null,
    "connectionStrings": null,
    "machineKey": null,
    "handlerMappings": null,
    "documentRoot": null,
    "scmType": "None",
    "use32BitWorkerProcess": true,
    "webSocketsEnabled": false,
    "alwaysOn": false,
    "javaVersion": null,
    "javaContainer": null,
    "javaContainerVersion": null,
    "appCommandLine": "",
    "managedPipelineMode": "Integrated",
    "virtualApplications": [
      {
        "virtualPath": "/",
        "physicalPath": "site\\wwwroot",
        "preloadEnabled": false,
        "virtualDirectories": null
      }
    ],
    "winAuthAdminState": 0,
    "winAuthTenantState": 0,
    "customAppPoolIdentityAdminState": false,
    "customAppPoolIdentityTenantState": false,
    "runtimeADUser": null,
    "runtimeADUserPassword": null,
    "loadBalancing": "LeastRequests",
    "routingRules": [],
    "experiments": {
      "rampUpRules": []
    },
    "limits": null,
    "autoHealEnabled": false,
    "autoHealRules": null,
    "tracingOptions": null,
    "vnetName": "",
    "siteAuthEnabled": false,
    "siteAuthSettings": {
      "enabled": null,
      "unauthenticatedClientAction": null,
      "tokenStoreEnabled": null,
      "allowedExternalRedirectUrls": null,
      "defaultProvider": null,
      "clientId": null,
      "clientSecret": null,
      "issuer": null,
      "allowedAudiences": null,
      "additionalLoginParams": null,
      "isAadAutoProvisioned": false,
      "googleClientId": null,
      "googleClientSecret": null,
      "googleOAuthScopes": null,
      "facebookAppId": null,
      "facebookAppSecret": null,
      "facebookOAuthScopes": null,
      "twitterConsumerKey": null,
      "twitterConsumerSecret": null,
      "microsoftAccountClientId": null,
      "microsoftAccountClientSecret": null,
      "microsoftAccountOAuthScopes": null
    },
    "cors": null,
    "push": null,
    "apiDefinition": {
      "url": "[concat('https://', variables('FunctionPlanNameMyStuff'), '.azurewebsites.net/swagger/docs/v1')]"
    },
    "autoSwapSlotName": null,
    "localMySqlEnabled": false,
    "managedServiceIdentityId": null,
    "ipSecurityRestrictions": null,
    "http20Enabled": false,
    "minTlsVersion": "1.0"
  },
  "dependsOn": [
    "[resourceId('Microsoft.Web/sites', variables('FunctionSiteNameMyStuff'))]"
  ]
},

3 个答案:

答案 0 :(得分:1)

将此应用程序设置添加到您的模板中:

{ "name": "WEBSITE_RUN_FROM_PACKAGE", "value": "1" }

仅在存在此设置的情况下才能从zip文件运行功能,而重新部署没有此功能的模板将删除该设置的现有值(如果有)。

答案 1 :(得分:0)

您的ARM模板有问题,因为它会将应用程序设置设置为与应用程序创建不同的操作,这在使用Azure文件时不受支持。

有关指导,请参见this sample

答案 2 :(得分:0)

Murray的答案确实有用,但是它确实需要一个以上的班轮,所以我在这里进行扩展。

在我的ARM模板中添加了一些CORS来源后,我遇到了这个问题,当我运行模板时,它删除了功能,要对其进行修复,您需要执行以下操作(这假定您使用的是基于Windows的功能应用程序,因此以及您正在从Azure DevOps进行部署)

  1. 将WEBSITE_RUN_FROM_PACKAGE设置添加到函数的应用程序服务设置中并将其设置为1(也可以设置为该包所在的URL,但会对函数应用程序的冷启动产生负面影响)
  2. 现在在您的Azure DevOps发布管道中令人困惑的是,将部署方法设置为“ zip部署”而不是“从程序包运行”!
  3. 通过更改重新运行ARM模板现在不会删除该站点

功能应用程序现在将从zip文件运行,而不是直接从wwwroot文件夹中的部署运行,这意味着wwwroot文件夹变为只读。如果您尝试在此处进行任何编辑,都会出现错误:

enter image description here

这种方法的好处是您不能一半部署您的应用程序,并且只将其读取为只读,这意味着一旦部署它就不会意外地弄乱它。

以上内容无法像更改插槽那样顺畅地进行,并且需要重新启动该应用程序,因此它需要与登台应用程序或插槽一起使用,尽管撰写本文时仍在功能应用程序的预览中。

原始github公告值得一读here,因为它们比docs更详细。