Azure Function部署不使用VS Code扩展

uhry853o  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(74)

我正在尝试部署Azure Function执行简单计算。它部署成功,因为我可以看到 * 您的Functions 4.0应用程序已启动并运行 *。我的逻辑(inspired by this)设置如下。

import azure.functions as func
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="addition")
def main(req: func.HttpRequest) -> str:
    a = req.params.get("a")
    b = req.params.get("b")
    return "{}".format(int(a) * int(b))

当我导航到/api/addition?a=2&b=3时,我没有看到预期的结果。404找不到
我试过使用VS Code Azure Function extension进行部署。这是成功的,我可以在屏幕上确认预期的结果。但是我不想用VS Code。我错过了什么?谷歌搜索它是具有挑战性的,因为每个人都问如何在VS代码中做到这一点。
buildpipe的编译大致如下。

- task: UsePythonVersion@0
  inputs:
    versionSpec: $(pythonVersion)
    disableDownloadFromRegistry: true
    addToPath: true
    architecture: 'x64'
  displayName: 'Use python $(pythonVersion)'
- script: |
    python -m venv antenv
    source antenv/bin/activate
    pip install -r requirements.txt
  workingDirectory: $(projectRoot)
  displayName: 'Install requirements'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(projectRoot)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

- publish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
  artifact: drop

然后,它像这样展开。

- task: UsePythonVersion@0
  inputs:
    versionSpec: $(pythonVersion)
    disableDownloadFromRegistry: true
    addToPath: true
    architecture: 'x64'
    displayName: 'Use python $(pythonVersion)'
          
- task: AzureFunctionApp@2
  inputs:
    azureSubscription: $(azureSubscription)
    appType: 'functionAppLinux'
    appName: 'func-calculationtest'
    package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
    runtimeStack: 'PYTHON|3.10'
    deploymentMethod: 'auto'
of1yzvn4

of1yzvn41#

我用你的代码创建了一个Azure Functions PythonV 2 Http触发器,它可以做简单的加法,将代码推送到Azure存储库,并通过Azure DevOps将其部署到Function应用程序,如下所示:

  • 从DevOps yaml模板中选择以下选项并部署Function应用:-*

Yaml code:-

trigger:
- master

variables:
  
  azureSubscription: 'correct-serviceconnection'

  
  functionAppName: 'siliconfunc58'

  
  vmImageName: 'ubuntu-latest'

  
  workingDirectory: '$(System.DefaultWorkingDirectory)'

stages:
- stage: Build
  displayName: Build stage

  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)

    steps:
    - bash: |
        if [ -f extensions.csproj ]
        then
            dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
        fi
      workingDirectory: $(workingDirectory)
      displayName: 'Build extensions'

    - task: UsePythonVersion@0
      displayName: 'Use Python 3.6'
      inputs:
        versionSpec: 3.10 # Functions V2 supports Python 3.6 as of today

    - bash: |
        pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
      workingDirectory: $(workingDirectory)
      displayName: 'Install application dependencies'

    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(workingDirectory)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()

  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: 'development'
    pool:
      vmImage: $(vmImageName)

    strategy:
      runOnce:
        deploy:

          steps:
          - task: AzureFunctionApp@1
            displayName: 'Azure functions app deploy'
            inputs:
              azureSubscription: '$(azureSubscription)'
              appType: functionAppLinux
              appName: $(functionAppName)
              package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'

输出:-

相关问题