使用 DevOps 部署 Python 函数应用程序是移动文件,但不是实际部署应用程序

问题描述 投票:0回答:1

这是这个问题的转发,https://learn.microsoft.com/en-us/answers/questions/1462841/deploying-python-function-application-with-devops 添加到 SO 以获得更多观看次数。

使用 VS Code 并按照下面链接的 Microsoft 文章创建了 Python Azure 函数(模型 V2),并使用函数应用程序的默认代码。

https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python?pivots=python-mode-decorators

使用下面链接的文章(已有几年历史)在 Azure DevOps 中设置了构建管道和发布管道。发布管道中的任务与文章不同,但其他一切似乎都进展顺利。

https://medium.com/globant/how-to-create-and-deploy-a-python-azure-function-using-azure-devops-ci-cd-2aa8f8675716

从当前可用的任务来看,“Azure Function Deploy”任务似乎是最好且唯一合适的。下面的屏幕截图显示了可用的任务。

当Release Pipeline运行时,运行成功。根据下面的屏幕截图,所有文件都已移动到功能应用程序服务。它运行了多次,编辑了默认的“function_app.py”文件中的注释,并添加了新文件以确保构建管道 + 部署管道正在移动文档。

但是,没有实际的函数在运行并且可以与之交互。 (参见下面的屏幕截图)。您知道部署管道中需要进行哪些修改才能使其正常工作吗?

python azure-devops azure-functions azure-pipelines azure-pipelines-release-pipeline
1个回答
0
投票

我按照相同的文档创建了 python 函数应用程序,并通过 DevOps 管道部署它,它在我这边工作得很好。

请按照以下步骤进行检查:

  1. 创建函数应用程序后,您可以在azure上创建一个测试函数应用程序,并直接从VS代码部署它,确保函数应用程序正常工作,这将验证您是否拥有正确的代码。详细步骤这里这里

  1. 一旦确认测试功能应用程序正在运行,您就可以将代码推送到 DevOps 存储库。在 azure 上创建目标函数应用服务。文档使用 Azure Pipelines 持续交付中提到了部署步骤。按照文档创建 yaml 管道(推荐),其与经典 UI 编辑器管道相同。

我在创建函数应用程序时使用了 python 3.11,因此我在管道上指定了 3.11。我的yaml供您参考。

trigger: none

pool:
  vmImage: ubuntu-latest

variables:
  # Azure service connection established during pipeline creation
  azureSubscription: YourAzureResourceServiceConnection
  appName: functionappname

steps:
- task: UsePythonVersion@0
  displayName: "Setting Python version to yours"
  inputs:
    versionSpec: '3.11'
    addToPath: true
    architecture: 'x64'
- bash: |
    if [ -f extensions.csproj ]
    then
        dotnet build extensions.csproj --output ./bin
    fi
    pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
- task: ArchiveFiles@2
  displayName: "Archive files"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
    artifactName: 'drop'

- task: AzureFunctionApp@2 # Add this at the end of your file
  inputs:
    azureSubscription: $(azureSubscription)
    appType: functionAppLinux # default is functionApp
    appName: $(appName)
    package: $(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip
    deploymentMethod: 'auto' # 'auto' | 'zipDeploy' | 'runFromPackage'. Required. Deployment method. Default: auto.

© www.soinside.com 2019 - 2024. All rights reserved.