如何使用 REST API 或 ARM 模板通过私有 GitHub 存储库在应用服务中部署应用?

Posted

技术标签:

【中文标题】如何使用 REST API 或 ARM 模板通过私有 GitHub 存储库在应用服务中部署应用?【英文标题】:How Can I deploy Apps in app service with private GitHub repository using REST API or ARM templates? 【发布时间】:2021-04-01 20:36:36 【问题描述】:

以下是我用来创建应用服务并使用私有 GitHub 存储库部署应用程序的 ARM 模板,但应用程序部署失败。


               "properties": 
               "mode": "Incremental",
               "template":
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.1",
                "parameters": 
                    "siteName": 
                        "type": "string",
                        "defaultValue": "[concat(\'WebApp-\', uniqueString(resourceGroup().id))]",
                        "metadata": 
                            "description": "The name of you Web Site."
                        
                    ,
                    "location": 
                        "type": "string",
                        "defaultValue": "[resourceGroup().location]",
                        "metadata": 
                            "description": "Location for all resources."
                        
                    ,
                    "sku": 
                        "type": "string",
                        "allowedValues": [
                            "F1",
                            "D1",
                            "B1",
                            "B2",
                            "B3",
                            "S1",
                            "S2",
                            "S3",
                            "P1",
                            "P2",
                            "P3",
                            "P4"
                        ],
                        "defaultValue": "F1",
                        "metadata": 
                            "description": "The pricing tier for the hosting plan."
                        
                    ,
                    "workerSize": 
                        "type": "string",
                        "allowedValues": [
                            "0",
                            "1",
                            "2"
                        ],
                        "defaultValue": "0",
                        "metadata": 
                            "description": "The instance size of the hosting plan (small, medium, or large)."
                        
                    ,
                    "repoURL": 
                        "type": "string",
                        "defaultValue": "https://github.com/Azure-Samples/app-service-web-html-get-started.git",
                        "metadata": 
                            "description": "The URL for the GitHub repository that contains the project to deploy."
                        
                    ,
                    "branch": 
                        "type": "string",
                        "defaultValue": "master",
                        "metadata": 
                            "description": "The branch of the GitHub repository to use."
                        
                    
                ,
                "variables": 
                    "hostingPlanName": "jhyhfgljgljuhg-Plan"
                ,
                "resources": [
                    
                        "type": "Microsoft.Web/serverfarms",
                        "apiVersion": "2020-06-01",
                        "name": "[variables(\'hostingPlanName\')]",
                        "location": "[parameters(\'location\')]",
                        "sku": 
                            "name": "[parameters(\'sku\')]",
                            "capacity": "[parameters(\'workerSize\')]"
                        ,
                        "properties": 
                            "name": "[variables(\'hostingPlanName\')]"
                        
                    ,
                    
                        "type": "Microsoft.Web/sites",
                        "apiVersion": "2020-06-01",
                        "name": "[parameters(\'siteName\')]",
                        "location": "[parameters(\'location\')]",
                        "identity": 
                            "type": "SystemAssigned"
                      ,
                        "dependsOn": [
                            "[resourceId(\'Microsoft.Web/serverfarms\', variables(\'hostingPlanName\'))]"
                        ],
                        "properties": 
                            "serverFarmId": "[variables(\'hostingPlanName\')]"
                        ,
                        "resources": [
                            
                                "type": "sourcecontrols",
                                "apiVersion": "2020-06-01",
                                "name": "web",
                                "location": "[parameters(\'location\')]",
                                "dependsOn": [
                                    "[resourceId(\'Microsoft.Web/sites\', parameters(\'siteName\'))]"
                                ],
                                "properties": 
                                    "repoUrl": "[parameters(\'repoURL\')]",
                                    "branch": "[parameters(\'branch\')]",
                                    "isManualIntegration": true,
                                    "ScmType":"Git"
                                
                            
                        ]
                    
                ]
            ,
               "parameters": 
                 "siteName": 
                   "value":"trouble1appservice"
               ,
                 "repoUrl": 
                "value":"https://trouble1fake:8f0276be40aaed284ac8862d198fb1e1a17f727f@github.com/trouble1fake/uploadfile"
             ,
        "sku": 
              "value": "B1"
            ,
            "workerSize": 
              "value": "0"
            ,
            "branch": 
              "value": "master"
            
                    
                
            
        

repoUrl 我使用的是 https://trouble1fake:8f0276be40aaed284ac8862d198fb1e1a17f727f@github.com/trouble1fake/uploadfile

仍然无法正常工作。 或者有什么方法可以使用rest api执行命令或导入文件?

【问题讨论】:

【参考方案1】:

这不是它的工作方式。您必须先创建 GitHub 解决方案的工件,然后部署它(无论是本地还是管道)。请参考以下方法并选择您想要的方法:

    您可以使用Visual Studio 部署您的应用,一旦它从您的私有存储库克隆到您的本地:Deploy an ASP.NET Web App in Azure App Service

    您可以使用 Azure DevOps 管道部署您的应用,其中您可以在 ADO 服务器中添加您的代码并按照分步流程部署应用:Deploying into Azure App Service using Azure DevOps CI/CD Pipeline。。 p>

【讨论】:

以上是关于如何使用 REST API 或 ARM 模板通过私有 GitHub 存储库在应用服务中部署应用?的主要内容,如果未能解决你的问题,请参考以下文章

通过Google Drive REST API上传或创建包含内容的新文件?

如何通过 PKCS#11 API 从 eToken 获取私钥?

在 HTML 页面或模板中使用 Django-REST-Framework 从在 Django 中创建的 API 获取/显示 API 数据

如何通过 PowerShell 或 ARM 模板在 Azure 数据资源管理器中创建表和摄取映射

是否可以通过自定义扩展或 REST API 添加新的工作项类型?

通过 Rest API 或自动化从性能中心或负载运行器分析中提取稳态性能测试结果?