使用CI-CD管道的Azure函数部署与VsCode部署不同

7eumitmz  于 2023-08-07  发布在  Vscode
关注(0)|答案(2)|浏览(142)

我正在Azure订阅上通过CI-CD管道部署Azure Python函数应用程序。但部署后,我在Azure Function门户中遇到问题
您的应用当前处于只读模式,因为您正在从包文件运行。若要进行任何更改,请更新zip文件中的内容和WEBSITE_RUN_FROM_PACKAGE应用程序设置。当我通过VsCode部署函数应用程序时,我没有得到错误。我已尝试更改应用程序设置以删除WEBSITE_RUN_FROM_PACKAGE问题,但问题仍然存在。通过CICD门户部署消费类应用程序是否存在缺点

parameters:
                              - name: environment
                                type: string
                                default: D
                                values:
                                  - D
                                  - Q
                                  - P
                            
                            trigger:
                            - none
                            variables:
                              azureSubscription: 'xxxx'
                              buildPlatform: 'Any CPU'
                              buildConfiguration: 'Release'
                              appName: 'xxxxxx'
                              
                            resources:
                              repositories:
                              - repository: self
                                type: git
                                ref: refs/heads/feature-cdqpipeline_upd
                            jobs:
                            - job: Job_1
                              displayName: Agent job 1
                              pool:
                                vmImage: ubuntu-latest
                              steps:
                              - checkout: self
                                fetchDepth: 1
                              - task: Bash@3
                                displayName: Build extensions
                                inputs:
                                  targetType: inline
                                  script: >-
                                    if [ -f extensions.csproj ]
                            
                                    then
                                        dotnet build extensions.csproj --output ./bin
                                    fi
                              - task: UsePythonVersion@0
                                displayName: Use Python 3.9
                                inputs:
                                  versionSpec: 3.9
                                  allowUnstable: true
                              - task: Bash@3
                                displayName: Install Application Dependencies
                                inputs:
                                  targetType: inline
                                  script: >-
                                    python3.9 -m venv worker_venv
                            
                                    source worker_venv/bin/activate
                            
                                    pip3.9 install setuptools
                            
                                    pip3.9 install -r requirements.txt
                              - task: ArchiveFiles@2
                                displayName: Archive files
                                inputs:
                                  rootFolderOrFile: AzFunct
                                  includeRootFolder: false
                                  
                              - task: PublishBuildArtifacts@1
                                displayName: 'Publish Artifact: drop'
                               
                              - task: AzureFunctionApp@1 # Add this at the end of your file
                                inputs:
                                  azureSubscription: '${{variables.azureSubscription}}'
                                  appType: functionAppLinux # default is functionApp
                                  appName: 'xxxxxxxx'
                                  
                                  package: $(System.ArtifactsDirectory)/**/*.zip
                                  deploymentMethod: 'zipDeploy'
                                #Uncomment the next lines to deploy to a deployment slot
                                #Note that deployment slots is not supported for Linux                                          #deployToSlotOrASE: true
                                #resourceGroupName: '<Resource Group Name>'
                                #slotName: '<Slot name>'    
                            ...

字符串

bjg7j2ky

bjg7j2ky1#

这不是一个错误:


的数据
此消息只是说您可以通过构建管道中的此步骤更新您的函数应用程序:

- task: AzureFunctionApp@1 # Add this at the end of your file
   inputs:
     azureSubscription: '${{variables.azureSubscription}}'
     appType: functionAppLinux # default is functionApp
     appName: 'xxxxxxxx'
     package: $(System.ArtifactsDirectory)/**/*.zip
     deploymentMethod: 'zipDeploy'

字符串

ffdz8vbo

ffdz8vbo2#

我同意@Shamrai Aleksander的观点,这个警告是警告,而不是错误。
对于您在评论中分享的错误消息:-
失败例外:ModuleNotFoundError:没有名为“requests”的模块
在部署Function应用之前,确保requests包存在于requirements.txt中。此外,如果它存在并且部署导致错误,请将其从requirements.txt中删除并再次执行CI/CD管道部署。我尝试在requirements.txt中添加requests包,并成功地部署了Http触发器函数,并在其下面运行了YAML脚本。

我的需求.txt:-

azure-functions
requests

字符串
除此之外,请尝试使用下面的YAML脚本来部署您的函数,在此脚本中,requirements.txt中的所有依赖项都已正确安装:-

trigger:
- master

variables:
  # Azure Resource Manager connection created during pipeline creation
  azureSubscription: 'subid'

  # Function app name
  functionAppName: 'siliconfunc32'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

  # Working Directory
  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.10'
      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'

输出:-

x1c 0d1x的数据
我的函数得到了部署与警告,但仍然与代码+测试的功能,并成功运行,参考如下:-





如果错误仍然存在,请检查您的init.py代码并验证请求模块是否正确导入(如果您使用的是自定义代码)。

相关问题