【问题标题】:Deploy app settings to azure function app将应用设置部署到 azure 函数应用
【发布时间】:2017-08-01 08:10:10
【问题描述】:

在寻找一种方法来部署我的应用程序的自定义应用程序设置时需要帮助 - 1. 使用我的 .funproj 创建的 appsettings.json(与 2015 年的工具相比) 2.appveyor的环境变量 3.任何其他技巧

我想要的只是避免在门户中手动设置这些内容并对其进行源代码控制(更好 - 使用部署,例如 - appveyor 的安全环境变量)

提前致谢! 以下是我定位的门户设置示例 -

appveyor的环境变量设置示例-

environment:
    SolutionDir: $(APPVEYOR_BUILD_FOLDER)\
    my_var1: value1
    my_var2: value2

函数应用 (run.csx) 中的示例用法 -

using System;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;

public static void Run(string input, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {input}");
    log.Info($"This is a custom setting: {GetEnvironmentVariable("my_var1")}");
}

public static string GetEnvironmentVariable(string name)
{
    return name + ": " +
        System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
}

【问题讨论】:

  • appveyor 如何部署这个? ARM 模板?
  • 使用网络部署
  • 也许您可以按照here 描述的after_deploy 脚​​本使用Azure PowerShell(已安装在构建工作人员上)?
  • Here 是一些关于如何在 AppVeyor 上安全使用 Azure PowerShell 的示例。

标签: azure azure-functions appveyor


【解决方案1】:

您可以通过手臂模板来做到这一点。执行此操作的示例手臂模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "functionappname": {
      "type": "string"
    }
  },
  "variables": {
    "serviceplanname": "[concat('functionserviceplan-',parameters('functionappname'),'-', uniqueString(resourceGroup().id))]",
    "functionstoragename": "[substring(toLower(concat('st',parameters('functionappname'), uniqueString(resourceGroup().id))),0,24)]"
  },
  "resources": [
    {
        "name": "[variables('serviceplanname')]",
        "type": "Microsoft.Web/serverfarms",
        "kind": "functionapp",
        "sku": {
            "name": "Y1",
            "tier": "Dynamic",
            "size": "Y1",
            "family": "Y",
            "capacity": 0
        },
        "apiVersion": "2015-08-01",
        "location": "[resourceGroup().location]",
        "properties": { "name": "[variables('serviceplanname')]" }
    },
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('functionstoragename')]",
      "apiVersion": "2016-01-01",
      "sku": { "name": "Standard_LRS" },
      "location": "[resourceGroup().location]",
      "kind": "Storage"
    },
    {
        "type": "Microsoft.Web/sites",
        "kind": "functionapp",
        "name": "[parameters('functionappname')]",
        "apiVersion": "2015-08-01",
        "location": "[resourceGroup().location]",
        "properties": {
            "name": "[parameters('functionappname')]",
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('serviceplanname'))]",
            "hostNames": [ "[concat(parameters('functionappname'),'.azurewebsites.net')]" ],
            "enabledHostNames": [
                "[concat(parameters('functionappname'),'.azurewebsites.net')]",
                "[concat(parameters('functionappname'),'.scm.azurewebsites.net')]"
            ],
            "siteConfig": {
                "appSettings": [
                    { "name": "FUNCTIONS_EXTENSION_VERSION", "value": "~1" },
                    { "name": "AzureWebJobsDashboard", "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('functionstoragename'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('functionstoragename')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]" },
                    { "name": "AzureWebJobsStorage", "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('functionstoragename'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('functionstoragename')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]" },
                    { "name": "WEBSITE_NODE_DEFAULT_VERSION", "value": "6.5.0" }
                ]
            }
        },
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', variables('serviceplanname'))]",
            "[resourceId('Microsoft.Storage/storageAccounts', variables('functionstoragename'))]"
        ]
    }
  ]
}

您可以阅读如何从 VSTS 自动化部署:use-vsts-to-deploy-functions-as-infrastructure-as-code

【讨论】:

  • @lindydonna-msft 你有 Powershell 脚本示例吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-11
  • 1970-01-01
  • 2020-01-18
相关资源
最近更新 更多