简体   繁体   English

坚持基于 Linux 消费的 Azure 函数的 CI/CD 部署

[英]Stuck with CI/CD deploy of Linux Consumption based Azure Function

I made an Azure Function (Python), hosted with a Linux Consumption plan.我制作了一个 Azure 函数(Python),托管在 Linux 消费计划中。 The App Engine is located into a dev ressource group. App Engine 位于开发资源组中。 I would now like to be able to deploy it (and subsequent changes) to the staging and prod ressource groups.我现在希望能够将它(以及后续更改)部署到 staging 和 prod 资源组。 The documentation on the many differents ways to do it has got me confused, especially with the fact that most of the deployment methods (deployment slots...) are not available with the Linux Consumption plan and I have no use for the Premium one.有关执行此操作的许多不同方法的文档让我感到困惑,尤其是大多数部署方法(部署槽...)在 Linux Consumption 计划中不可用,而我对 Premium 计划没有用处。 I thought of setting up a version control but I cannot link my Azure Function to an Azure DevOps repo (Deploy Center is disabled, grey).我想设置一个版本控制,但我无法将我的 Azure 函数链接到 Azure DevOps 存储库(部署中心已禁用,灰色)。

How would you do it?你会怎么做? Ideally with Azure DevOps.理想情况下使用 Azure DevOps。

Thanks in advance提前致谢

First of, you need to make sure that you have access to the subscription in question, with the resource groups and function apps.首先,您需要确保您有权访问有问题的订阅,以及资源组和函数应用。

Azure 开发运营

Build建造
On DevOps, for the project containing the repository, go to Pipelines > Pipelines (highlighted with red).在 DevOps 上,对于包含存储库的项目,转到 Pipelines > Pipelines(以红色突出显示)。
In the top-right corner, you should be able to see and click "New pipeline".在右上角,您应该能够看到并单击“新建管道”。 I'll be doing an "Azure Repos Git (YAML)" pipeline in this answer, so you might as well go along with.我将在这个答案中做一个“Azure Repos Git (YAML)”管道,所以你不妨一起去。 If you have any other particular preferences, then just make sure you change what needs to be changed accordingly.如果您有任何其他特定偏好,那么只需确保相应地更改需要更改的内容。 Our goal is basically just to publish an artifact from our build-process, which will in turn be consumed by a "Release pipeline".我们的目标基本上只是从我们的构建过程中发布一个工件,然后由“发布管道”使用。

Moving along, for the build pipeline, choosing "Azure Repos Git (YAML)" will prompt you to choose which repository in your project, that will 1) contain the YAML file we're about to create, and 2) have the source code available for the pipeline.继续前进,对于构建管道,选择“Azure Repos Git (YAML)”将提示您选择项目中的哪个存储库,它将 1) 包含我们将要创建的 YAML 文件,以及 2) 拥有源代码可用于管道。 Without going into too much detail, it is also possible to place all yaml-pipeline files into its own repository, and then include (via resources) the repositories containing the source code.无需赘述,也可以将所有 yaml-pipeline 文件放入其自己的存储库中,然后(通过资源)包含包含源代码的存储库。

Next Step is to "Configure your pipeline".下一步是“配置您的管道”。 There is actually a "Python Function App to Linux on Azure" template available.实际上有一个“Python Function App to Linux on Azure”模板可用。 However, it contains deployment stages as well, and I generally always put all deployment related into my "Release pipeline".但是,它也包含部署阶段,我通常总是将所有与部署相关的内容放入我的“发布管道”中。 For now, though, I went with the "Starter pipeline".不过,就目前而言,我选择了“入门管道”。
An online editor will actually pop up.实际上会弹出一个在线编辑器。 Towards the top of the editro, you'll see the repository's name and a "azure-pipelines.yml".在编辑器的顶部,您将看到存储库的名称和“azure-pipelines.yml”。 Click on the "azure-pipelines.yml" to rename the pipeline, as well as the name of the yaml-file, that'll end up in the repository's root.单击“azure-pipelines.yml”以重命名管道以及 yaml 文件的名称,该文件最终将位于存储库的根目录中。
I've put up a version of the aforementioned template, boiled down to what is necessary, and it's available here .我已经提供了上述模板的一个版本,归结为必要的内容,可在此处获得 Simply delete whatever is already in the "starter pipeline", and copy-paste the contents of the pastebin, into the pipeline.只需删除“启动管道”中已有的任何内容,然后将 pastebin 的内容复制粘贴到管道中。

When you save the pipeline, you probably want to put it into a different branch to begin with instead of your master branch (it will prompt you for it), and then create a PR.当您保存管道时,您可能希望将其放入一个不同的分支,而不是您的主分支(它会提示您输入),然后创建一个 PR。 Accept the PR when the pipeline works (you can run the pipeline using your newly created branch).管道工作时接受 PR(您可以使用新创建的分支运行管道)。 When the build pipeline successfully runs without errors, you should be able to see an artifact published, if you navigate to your successful run's overview (highlighted with red).当构建管道成功运行且没有错误时,如果您导航到成功运行的概述(以红色突出显示),您应该能够看到已发布的工件。 You can click and examine the contents to check if they are as expected.您可以单击并检查内容以检查它们是否符合预期。

构建管道概述

Release释放
Go to "Releases" (highlighted with green, first picture).转到“发布”(以绿色突出显示,第一张图片)。 From here, you should be able to see and click a "+ New"-button.从这里,您应该能够看到并单击“+ 新建”按钮。

添加新的发布管道

It will immediately prompt you to select what type of job you want.它会立即提示您选择您想要的工作类型。 Just click "Empty job" to begin with.只需单击“空作业”即可开始。
First choose an artifact to consume.首先选择要消耗的神器。 Click the "Add an artifact"-box to the left.单击左侧的“添加工件”框。 Find the pipeline you just created from the drop-down list.从下拉列表中找到您刚刚创建的管道。 You can configure the version to use (if you have certain preferences), and give the artifact an alias that can be used throughout the release pipeline.您可以配置要使用的版本(如果您有某些偏好),并为工件指定一个别名,以便在整个发布管道中使用。
Next is to setup your stages.接下来是设置您的阶段。 You want 3 stages: a stage for development, a stage for staging, and lastly, a stage for production.您需要 3 个阶段:一个开发阶段,一个分期阶段,最后一个生产阶段。 Currently you should have a "Stage 1".目前你应该有一个“第一阶段”。 If you hover above the stage, you can see a "+"-sign below the box.如果您将鼠标悬停在舞台上方,您可以在框下方看到一个“+”号。 Click it to add a stage.单击它以添加阶段。 Choose empty job again.再次选择空作业。 Repeat this for the newly created stage box (hover, click +, add empty job).对新创建的舞台框重复此操作(悬停,单击 +,添加空作业)。
You should now have something like this:你现在应该有这样的东西:

分期

Let's start by configuring stage 1. Click the stage (the box itself), and name it "Development" or something of your preference.让我们从配置阶段 1 开始。单击阶段(框本身),并将其命名为“开发”或您喜欢的名称。 Then click the "1 job, 0 task"-link.然后单击“1 个作业,0 个任务”链接。 Click the "Agent job"-box, and configure the agent job, as you see fit (make sure the agent downloads your artifact, it can be configured in the "Artifact download").单击“代理作业”框,并根据需要配置代理作业(确保代理下载您的工件,它可以在“工件下载”中进行配置)。
Next, click the "+"-sign on the agent job you just configured.接下来,单击您刚刚配置的代理作业上的“+”号。 From the prompt, use the search-bar to find "Azure Functions".根据提示,使用搜索栏查找“Azure 函数”。 Note, there are 3 jobs called this.请注意,有 3 个作业称为 this。 You want the one that is just called "Azure Functions".你想,这只是所谓的“天青功能”的一个。 Click and configure the newly created job.单击 并配置新创建的作业。 It should really be straight-forward here.这里应该很简单。 Pick function app on linux and find your "development" function app from the list.在 linux 上选择函数应用程序并从列表中找到您的“开发”函数应用程序。 The "Package or folder" should be something like $(System.DefaultWorkingDirectory)/**/*.zip by default, and it should suffice, unless you have done some customization to your build pipeline's artifact.默认情况下,“包或文件夹”应该类似于$(System.DefaultWorkingDirectory)/**/*.zip ,它应该足够了,除非您对构建管道的工件进行了一些自定义。
You should have something like this:你应该有这样的事情:

发展阶段

Azure 函数任务

From the "Tasks"-dropdown (with the red warning circle), you can move to "Stage 2" (you'll of course rename this as you did with "Stage 1" to "Development").从“任务”下拉列表(带有红色警告圆圈),您可以移动到“阶段 2”(当然,您可以像使用“阶段 1”那样将其重命名为“开发”)。 Since you're not using slots, swapping is unfortunately not possible between 2 function apps, in two different resource groups - at least not by my knowledge.由于您没有使用插槽,因此很遗憾无法在两个不同资源组中的 2 个函数应用程序之间进行交换 - 至少据我所知不是这样。 So you'll have to repeat the entire process from the "Development" stage, where you use the artifact to deploy to the function app in the staging resource group.因此,您必须从“开发”阶段开始重复整个过程,在该阶段使用工件部署到暂存资源组中的函数应用程序。 The same goes for your last stage "Stage 3", where you deploy to your function app in your production resource group.这同样适用于最后一个阶段“第 3 阶段”,在该阶段部署到生产资源组中的函数应用。

Staging and approval分期和批准
What we've been waiting for, I imagine.我们一直在等待什么,我想。 From the picture with the stages overview, you can see that each stage has 2 attached "buttons" on each side of the box.从带有阶段概述的图片中,您可以看到每个阶段在框的每一侧都有 2 个附加的“按钮”。 When with a lightning and a user icon (left), and one with just a user icon.当有闪电和用户图标(左),只有一个用户图标时。 The one on the left is "pre-stage actions", while the on the right is "post-stage actions".左边是“前阶段动作”,右边是“后阶段动作”。 In your scenario, you probably want to configure "pre-stage actions" for your "Stage 2"/"Staging" and for "Stage 3"/"Production".在您的场景中,您可能希望为“第 2 阶段”/“分期”和“第 3 阶段”/“生产”配置“前阶段操作”。 In both cases, I'd add "Pre-deployment approvals", like this:在这两种情况下,我都会添加“预部署批准”,如下所示:

部署前批准

You can add specific persons, or entire groups.您可以添加特定人员或整个组。 It will require that someone then goes to the release pipeline overview, and then approves the next stage, before it will be deployed (or rather, the stage won't start before it has been approved).它将要求有人然后转到发布管道概述,然后在部署之前批准下一阶段(或者更确切地说,该阶段在批准之前不会开始)。

Phew, that was a long one... I hope this cleared some of the confusion you have had, and that it works out for you.呼,那太长了……我希望这能消除您的一些困惑,并且对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 CI/CD 管道将 Azure 函数部署到函数应用中? - How to deploy an Azure function into a function app through a CI/CD pipeline? Gitlab CI/CD 部署到 Azure Web 服务 - Gitlab CI/CD deploy to Azure Web Service Is it possible to do continuous deployment CI/CD of an Azure Function through a Linux Environment via Azure DevOps? - Is it possible to do continuous deployment CI/CD of an Azure Function through a Linux Environment via Azure DevOps? Azure DevOps CI/CD 部署 Web 或 Function 应用程序更改 Z9463F832F8B5261Z 管道中的应用程序设置中的值FBD8403F8185CABED1FCE - Azure DevOps CI/CD Deploy Web or Function App changing the values in appsettings in YAML Pipelines Azure function Linux 消费计划位数 - Azure function Linux consumption plan bitness 在 Azure 上为 Azure Python 函数设置 CI/CD 管道 - Setting up CI/CD Pipeline on Azure for Azure Python Function 基于特定文件的 Azure CI/CD 触发管道 - Azure CI/CD trigger pipeline based on specific file 在CI / CD之后找不到Azure功能API - Azure Function APIs cannot be found after CI/CD CI-CD Azure devops 用于 function 应用程序部署 - CI-CD Azure devops for function app deployment 如何使用 CI 管道部署 Azure Function? - How to deploy a Azure Function using a CI pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM