如何在 ARM 模板中配置部署中心配置?

huangapple go评论99阅读模式
英文:

How to configure Deployment Center configuration in ARM Template?

问题

我通过GitHub Action工作流创建了一个“Function App”,并从Azure创建了一个ARM模板。这是一个CI/CD工作流程。

要直接部署“Function App”,我手动转到“部署中心”并连接到GitHub。然后获取“发布配置文件”设置,并更新GitHub密钥。

手动过程可以正常工作!但如果它是ARM模板的一部分,工作流会失败。

我在ARM模板中看到了以下部分:

{
    "type": "sourcecontrols",
    "name": "web",
    "apiVersion": "2020-12-01",
    "properties": {
        "RepoUrl": "[parameters('repoUrl')]",
        "branch": "[parameters('branch')]",
        "IsManualIntegration": false,
        "deploymentRollbackEnabled": false,
        "isMercurial": false,
        "isGitHubAction": true,
        "gitHubActionConfiguration": {
            "generateWorkflowFile": false,
            "workflowSettings": {
                "appType": "functionapp",
                "publishType": "code",
                "os": "linux",
                "runtimeStack": "dotnet",
                "workflowApiVersion": "2020-12-01",
                "slotName": "production",
                "variables": {
                    "runtimeVersion": "7.0.x"
                }
            }
        }
    },
    "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', parameters('name'))]"
    ]
}

但上述部分生成了错误:

错误: "status":"Failed","error":"code":"DeploymentFailed","target":"/subscriptions/f24b12b1-d887-4938-8c49-ce56acded667/resourceGroups/MyResourceGroup/providers/Microsoft.Resources/deployments/azure-function-api","message":"至少有一个资源部署操作失败。请列出详细的部署操作。请参阅https://aka.ms/arm-deployment-operations了解用法详细信息。","details":["code":"NotFound","target":"/subscriptions/f24b12b1-d887-4938-8c49-ce56acded667/resourceGroups/MyResourceGroup/providers/Microsoft.Resources/deployments/azure-function-api","message":"
\r\n  \"Code\": \"NotFound\",\r\n  \"Message\": \"无法找到名为GitHub的SourceControlToken。\",\r\n  \"Target\": null,\r\n  \"Details\": [\r\n    ***
      \"Message\": \"无法找到名为GitHub的SourceControlToken。\"\r\n    ***,
    ***
      \"Code\": \"NotFound\"\r\n    ***,
    ***
      \"ErrorEntity\": ***
        \"ExtendedCode\": \"51004\",
        \"MessageTemplate\": \"无法找到名为0的1。\",
        \"Parameters\": [
          \"SourceControlToken\",
          \"GitHub\"
        ],
        \"Code\": \"NotFound\",
        \"Message\": \"无法找到名为GitHub的SourceControlToken。\"
      ***
    ***
  ],
  \"Innererror\": null
***"]

我需要哪些配置才能通过上述错误?

除了手动步骤外,是否有ARM模板命令来获取GitHub仓库名称、分支并将密钥复制到“GitHub设置/秘密与变量”中作为“存储库秘密”?

英文:

I created a Function App through GitHub Action workflow and an ARM Template from Azure. It is a CI/CD workflow.

To deploy the Function App directly, I go to Deployment Center manually connect to GitHub. Then get the Publish Profile settings, and update the GitHub secret.

The manual process works! But if it is part of the ARM Template, the workflow fails.

如何在 ARM 模板中配置部署中心配置?

I see a section in the ARM Template like below:

{
                    "type": "sourcecontrols",
                    "name": "web",
                    "apiVersion": "2020-12-01",
                    "properties": {
                        "RepoUrl": "[parameters('repoUrl')]",
                        "branch": "[parameters('branch')]",
                        "IsManualIntegration": false,
                        "deploymentRollbackEnabled": false,
                        "isMercurial": false,
                        "isGitHubAction": true,
                        "gitHubActionConfiguration": {
                            "generateWorkflowFile": false,
                            "workflowSettings": {
                                "appType": "functionapp",
                                "publishType": "code",
                                "os": "linux",
                                "runtimeStack": "dotnet",
                                "workflowApiVersion": "2020-12-01",
                                "slotName": "production",
                                "variables": {
                                    "runtimeVersion": "7.0.x"
                                }
                            }
                        }
                    },
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('name'))]"
                    ]
                }

But the above generates the error:

ERROR: ***"status":"Failed","error":***"code":"DeploymentFailed","target":"/subscriptions/f24b12b1-d887-4938-8c49-ce56acded667/resourceGroups/MyResourceGroup/providers/Microsoft.Resources/deployments/azure-function-api","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[***"code":"NotFound","target":"/subscriptions/f24b12b1-d887-4938-8c49-ce56acded667/resourceGroups/MyResourceGroup/providers/Microsoft.Resources/deployments/azure-function-api","message":"***\r\n  \"Code\": \"NotFound\",\r\n  \"Message\": \"Cannot find SourceControlToken with name GitHub.\",\r\n  \"Target\": null,\r\n  \"Details\": [\r\n    ***\r\n      \"Message\": \"Cannot find SourceControlToken with name GitHub.\"\r\n    ***,\r\n    ***\r\n      \"Code\": \"NotFound\"\r\n    ***,\r\n    ***\r\n      \"ErrorEntity\": ***\r\n        \"ExtendedCode\": \"51004\",\r\n        \"MessageTemplate\": \"Cannot find ***0*** with name ***1***.\",\r\n        \"Parameters\": [\r\n          \"SourceControlToken\",\r\n          \"GitHub\"\r\n        ],\r\n        \"Code\": \"NotFound\",\r\n        \"Message\": \"Cannot find SourceControlToken with name GitHub.\"\r\n      ***\r\n    ***\r\n  ],\r\n  \"Innererror\": null\r\n***"***]***

What configuration that I need to have so I can pass the above error?

Instead of the manual step, are there ARM Template commands to get the GitHub repository name, branch and copy the secret to the GitHub Settings\Secrets & Variables as Repository secrets?

答案1

得分: 1

我尝试了以下的ARM模板,并在模板的源代码参数部分中添加了包含函数和分支的存储库URL,然后尝试部署它,函数触发器成功部署,参见以下链接:

ARM模板参考链接

如何在 ARM 模板中配置部署中心配置?

您可以在此处检查函数部署日志,查看是否需要更改任何设置,或者是否有任何阻止通过GitHub操作进行源代码部署的问题。

如何在 ARM 模板中配置部署中心配置?

函数触发器已成功从我的GitHub存储库部署如下:

添加了以下CORS设置:

如何在 ARM 模板中配置部署中心配置?

如何在 ARM 模板中配置部署中心配置?

要通过门户部署ARM模板,请使用以下方法:

在Azure门户中选择自定义部署 > 在编辑器中构建自己的模板 > 添加上述ARM模板并部署,请确保在参数中替换repo_urrl和branch为您自己的值:

如何在 ARM 模板中配置部署中心配置?

如何在 ARM 模板中配置部署中心配置?

点击保存,选择资源组 > 查看 + 创建 > 将部署函数应用与触发器:

如何在 ARM 模板中配置部署中心配置?

如何在 ARM 模板中配置部署中心配置?

英文:

I tried the below ARM Template and added my repository URL that contains the Function and Branch in the source control parameter section of the template and tried deploying it, The Function Trigger got deployed successfully, Refer below:-

ARM template reference Link

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appName": {
            "defaultValue": "[concat('funtionapp-', uniqueString(resourceGroup().id))]",
            "type": "string",
            "metadata": {
                "description": "The name of the function app that you wish to create."
            }
        },
        "sku": {
            "defaultValue": "S1",
            "type": "string",
            "metadata": {
                "description": "The pricing tier for the hosting plan."
            }
        },
        "workerSize": {
            "defaultValue": "0",
            "allowedValues": [
                "0",
                "1",
                "2"
            ],
            "type": "String",
            "metadata": {
                "description": "The instance size of the hosting plan (small, medium, or large)."
            }
        },
        "storageAccountType": {
            "defaultValue": "Standard_LRS",
            "allowedValues": [
                "Standard_LRS",
                "Standard_GRS",
                "Standard_ZRS",
                "Premium_LRS"
            ],
            "type": "string",
            "metadata": {
                "description": "Storage Account type"
            }
        },
        "repoURL": {
            "defaultValue": "https://github.com/username/FunctionApp25",
            "type": "string",
            "metadata": {
                "description": "The URL for the GitHub repository that contains the project to deploy."
            }
        },
        "branch": {
            "defaultValue": "master",
            "type": "string",
            "metadata": {
                "description": "The branch of the GitHub repository to use."
            }
        },
        "location": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location for all resources."
            }
        }
    },
    "variables": {
        "functionAppName": "[parameters('appName')]",
        "hostingPlanName": "[concat(parameters('appName'), '-plan')]",
        "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'functions')]"
    },
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2021-02-01",
            "name": "[variables('storageAccountName')]",
            "location": "[parameters('location')]",
            "sku": {
                "name": "[parameters('storageAccountType')]"
            },
            "kind": "Storage"
        },
        {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2020-12-01",
            "name": "[variables('hostingPlanName')]",
            "location": "[parameters('location')]",
            "sku": {
                "name": "[parameters('sku')]"
            },
            "properties": {
                "workerSize": "[parameters('workerSize')]",
                "numberOfWorkers": 1
            }
        },
        {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2020-12-01",
            "name": "[variables('functionAppName')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
            ],
            "kind": "functionapp",
            "properties": {
                "name": "[variables('functionAppName')]",
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                "clientAffinityEnabled": false,
                "siteConfig": {
                    "alwaysOn": true,
                    "cors": {
                        "allowedOrigins": [
                            "*"
                        ]
                    },
                    "appSettings": [
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~1"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value,';')]"
                        },
                        {
                            "name": "AzureWebJobsDashboard",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value,';')]"
                        }
                    ]
                }
            },
            "resources": [
                {
                    "type": "sourcecontrols",
                    "apiVersion": "2020-12-01",
                    "name": "web",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', variables('functionAppName'))]"
                    ],
                    "properties": {
                        "RepoUrl": "[parameters('repoURL')]",
                        "branch": "[parameters('branch')]",
                        "IsManualIntegration": true
                    }
                }
            ]
        }
    ]
}

如何在 ARM 模板中配置部署中心配置?

You can check your Function deployment logs here and see if any settings needs to be changed, or any issue that is stopping the deployment from source control via github actions.

如何在 ARM 模板中配置部署中心配置?

Function Trigger got deployed from my github repository successfully like below:-

Added CORS setting like below:-

如何在 ARM 模板中配置部署中心配置?

如何在 ARM 模板中配置部署中心配置?

In-order to deploy ARM template via Portal, Use the method below:-

Select Custom Deployment in Azure Portal > Build your own template in the editor> Add the ARM template above and deploy, Make sure you replace the repo_urrl and branch with yours in parameter:-

如何在 ARM 模板中配置部署中心配置?

如何在 ARM 模板中配置部署中心配置?

Click on Save, Select Resource Group > Review + Create > And the Function app with Trigger will be deployed:-

如何在 ARM 模板中配置部署中心配置?

如何在 ARM 模板中配置部署中心配置?

huangapple
  • 本文由 发表于 2023年7月20日 20:34:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729939.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定