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

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

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

我已经在下面复制了资源组部署脚本和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'))]"
  ]
},

最佳答案

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

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

如果存在此设置,则只能从zip文件运行功能,并且重新部署没有此设置的模板将删除该设置的现有值(如果有)。

关于azure-devops - 重新部署Azure Functions ARM模板会删除我发布的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52623262/

相关文章:

azure-devops - Azure DevOps的缩写是什么?

java - Azure 函数。从 VS Code 调试 java。无法连接到被调试虚拟机

c# - Azure 函数中的奇怪冲突

azure - 如何清除软删除的文本分析?

azure-devops - 如何完全清空或删除 VSTS 包提要?

azure - 具有项目间依赖关系的同一解决方案中的多个项目 - 使用 Azure DevOps 进行部署 - CI CD Pipeline

c# - 有没有一种方法可以在 azure 函数启动后立即调用通过依赖项注入(inject)注入(inject)的类中的方法?

azure - 使用 Azure 资源管理器模板将现有 Web 服务计划附加到新网站

azure - 使用 Azure ARM 模板创建 AKS 群集并部署我的 Kubernetes 应用程序

在 Azure DevOps 上构建 sqlproj