使用ARM模板部署Azure功能 [英] Deploy Azure Function with ARM template

查看:62
本文介绍了使用ARM模板部署Azure功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ARM模板部署Azure Function,但是我无法创建该函数本身.是否可以使用ARM模板创建实际功能?

I am trying to deploy Azure Function with ARM template , but I am not able to create the function itself. Is it possible to create the actual function using ARM template?

我已将该函数的源代码压缩并放置在公共位置,已将MSBuild部分添加到模板中,尽管部署成功完成-创建了App函数,但未创建函数本身

I have zipped the source code for the function and placed it in a public location, I have added the MSBuild section to the template and although the deployment finished successfully - the App function was created but not the function itself

这是模板

{
"parameters": {
    "name": {
        "type": "string"
    },
    "storageName": {
        "type": "string"
    },
    "location": {
        "type": "string"
    },
    "subscriptionId": {
        "type": "string"
    },
    "storage_account_endpoint": {
        "type": "string"
    }
},
"resources": [
    {
        "apiVersion": "2016-03-01",
        "name": "[parameters('name')]",
        "type": "Microsoft.Web/sites",
        "properties": {
            "name": "[parameters('name')]",
            "siteConfig": {
                "appSettings": [
                    {
                        "name": "FUNCTIONS_WORKER_RUNTIME",
                        "value": "node"
                    },
                    {
                        "name": "AzureWebJobsStorage",
                        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                    },
                    {
                        "name": "FUNCTIONS_EXTENSION_VERSION",
                        "value": "~2"
                    },
                    {
                        "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                    },
                    {
                        "name": "WEBSITE_CONTENTSHARE",
                        "value": "[concat(toLower(parameters('name')), 'bd58')]"
                    },
                    {
                        "name": "WEBSITE_NODE_DEFAULT_VERSION",
                        "value": "8.11.1"
                    },
                    {
                        "name": "storage_account_connection",
                        "value": "[parameters('storage_account_endpoint')]"
                    }
                ]
            },
            "clientAffinityEnabled": false,
            "reserved": false
        },
        "dependsOn": [
            "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
        ],
        "resources": [
            {
                "name": "MSDeploy",
                "type": "Extensions",
                "apiVersion": "2015-02-01",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('name'))]"
                ],
                "properties": {
                    "packageUri": "<URL to zip>"
                }
            }
        ],
        "location": "[parameters('location')]",
        "identity": {
            "type": "SystemAssigned"
        },
        "kind": "functionapp"
    },
    {
        "apiVersion": "2015-05-01-preview",
        "type": "Microsoft.Storage/storageAccounts",
        "name": "[parameters('storageName')]",
        "location": "[parameters('location')]",
        "properties": {
            "accountType": "Standard_LRS"
        }
    }
],
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0"
}

推荐答案

简而言之,否-ARM只能为您创建基础结构,而不能部署代码(**请参见注释). 但是一如既往,有一种方法.不久前,MS在网络应用程序(包括功能应用程序)上发布了一项新功能从ZIP运行".您只需要将实际项目(代码发布为ZIP)放置在功能应用可以访问它的位置即可.

In short No - ARM can only create the infrastructure for you but not deploy the code (**see comment). But as always there is a way. A while back MS release a new feature 'Run from ZIP' on web apps (including Function Apps). All you need is the actual project (code published as ZIP) to be in a location where the function app can access it.

我们将VSTS(Azure Dev Ops)用于CI/CD.因此,我们构建了将ZIP添加到工件的解决方案.然后,在发行版中,我们将ZIP复制到blob存储中,创建一个SAS令牌,然后将带有SAS令牌的blob容器的位置传递给ARM.在ARM模板中,我们使用输入参数构建到ZIP的连接字符串.一旦ARM完成,功能就会启动并运行.

We use VSTS (Azure Dev Ops) for CI/CD. So we build the solution add the ZIP to the artifact. Then in the Release we copy the ZIP to blob storage, create a SAS Token and pass the location of the blob Container with the SAS Token to ARM. In the ARM template we build the connection string to the ZIP, using input parameter. As soon as ARM is done then the Function is up and running.

例如.

{ 
"parameters": {
"name": {
    "type": "string"
},
"storageName": {
    "type": "string"
},
"location": {
    "type": "string"
},
"subscriptionId": {
    "type": "string"
},
"storage_account_endpoint": {
    "type": "string"
},
 "artifactsUri": {
  "type": "string"
},
"artifactsBlobContainer": {
  "type": "string"
},    
"artifactsLocationSasToken": {
  "type": "string"
}
},
"resources": [
{
    "apiVersion": "2016-03-01",
    "name": "[parameters('name')]",
    "type": "Microsoft.Web/sites",
    "properties": {
        "name": "[parameters('name')]",
        "siteConfig": {
            "appSettings": [
                {
                    "name": "FUNCTIONS_WORKER_RUNTIME",
                    "value": "node"
                },
                {
                    "name": "AzureWebJobsStorage",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                },
                {
                    "name": "FUNCTIONS_EXTENSION_VERSION",
                    "value": "~2"
                },
                {
                    "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                },
                {
                    "name": "WEBSITE_CONTENTSHARE",
                    "value": "[concat(toLower(parameters('name')), 'bd58')]"
                },
                {
                    "name": "WEBSITE_NODE_DEFAULT_VERSION",
                    "value": "8.11.1"
                },
                {
                    "name": "storage_account_connection",
                    "value": "[parameters('storage_account_endpoint')]"
                },
                {
                  "name": "WEBSITE_RUN_FROM_ZIP",
                  "value": "[concat(parameters('artifactsUri'), '/', parameters('artifactsBlobContainer'),'/','blahbla.FA.zip',parameters('artifactsLocationSasToken'))]"
                }
            ]
        },
        "clientAffinityEnabled": false,
        "reserved": false
    },
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
    ],
    "resources": [
        {
            "name": "MSDeploy",
            "type": "Extensions",
            "apiVersion": "2015-02-01",
            "dependsOn": [
                "[resourceId('Microsoft.Web/Sites', parameters('name'))]"
            ],
            "properties": {
                "packageUri": "<URL to zip>"
            }
        }
    ],
    "location": "[parameters('location')]",
    "identity": {
        "type": "SystemAssigned"
    },
    "kind": "functionapp"
},
{
    "apiVersion": "2015-05-01-preview",
    "type": "Microsoft.Storage/storageAccounts",
    "name": "[parameters('storageName')]",
    "location": "[parameters('location')]",
    "properties": {
        "accountType": "Standard_LRS"
    }
}
],
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0"
}

通过"WEBSITE_RUN_FROM_ZIP"应用设置可实现从ZIP运行". 希望这会有所帮助

'Run from ZIP' is achieved with the 'WEBSITE_RUN_FROM_ZIP' app setting. Hope this helps

这篇关于使用ARM模板部署Azure功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆