使用Azure管道将Python Flask应用部署到Azure Web应用,仅获取默认页

kyxcudwk  于 2023-06-24  发布在  Python
关注(0)|答案(1)|浏览(98)

我正在尝试使用Azure DevOps管道将Flask应用部署到Azure Web应用。管道是成功的,但不是获得应用程序主页,而是获得默认的Web应用程序主页。默认页面:defaultimage
我正在使用Microsoft的这个链接:https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python-webapp?view=azure-devops我还使用了他们为基本flask教程部署创建的相同存储库。(https://github.com/Microsoft/python-sample-vscode-flask-tutorial
我的yaml文件看起来像这样:

trigger:
- main

pool:
  vmImage: ubuntu-latest

stages:
  - stage: Deploy
    displayName: 'Deploy Stage'
    jobs:
      - job: DeploymentJob
        displayName: 'Deploy to Azure Web App'
        steps:
        - task: UsePythonVersion@0
          inputs:
              versionSpec: '3.9'
          displayName: 'Use Python 3.9'

        - script: |
              python -m venv antenv
              source antenv/bin/activate
              python -m pip install --upgrade pip
              pip install setup
              pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
          workingDirectory: $(Build.SourcesDirectory)
          displayName: "Install requirements"

        - task: ArchiveFiles@2
          inputs:
            rootFolderOrFile: '$(Build.SourcesDirectory)'
            includeRootFolder: false
            archiveType: 'zip'
            archiveFile: '$(Build.SourcesDirectory)/$(Build.BuildId).zip'
            replaceExistingArchive: true
        - task: PublishPipelineArtifact@1
          inputs:
            targetPath: '$(Build.ArtifactStagingDirectory)'
            artifactName: 'drop'
            publishLocation: 'pipeline'
          
        - task: DownloadBuildArtifacts@1
          inputs:
            buildType: 'current'
            downloadType: 'single'
            artifactName: 'drop'
            downloadPath: '$(System.ArtifactsDirectory)'
        
        - task: AzureWebApp@1
          inputs:
            appType : 'webApp'
            azureSubscription: 'azure-cloud-exampele'
            appName: 'xyz'
            package: '$(Build.SourcesDirectory)/$(Build.BuildId).zip'
            startUpCommand: 'gunicorn --bind=0.0.0.0 --workers=4 startup:app'

我对网站上提到的原始yaml文件做了一些修改。这是因为它给出了多个错误,每次构建都失败。有人能告诉我为什么它不能显示我的 flask 主页吗?我在过去的三天里一直在这上面:)

gkn4icbw

gkn4icbw1#

在尝试使用您的代码重现相同内容时,我发现PublishPipelineArtifact@1步骤和AzureWebApp@1步骤存在问题。
代码将文件存档在不同的位置(PublishPipelineArtifact@1),但发布了不同的文件夹($(Build.ArtifactStagingDirectory))。因此,即使管道是成功的,它实际上并没有产生任何工件。
我已经修改了你的管道代码如下,现在它是预期的工作。

trigger: none

pool:
  vmImage: ubuntu-latest

stages:
  - stage: Deploy
    displayName: 'Deploy Stage'
    jobs:
      - job: DeploymentJob
        displayName: 'Deploy to Azure Web App'
        steps:
        - task: UsePythonVersion@0
          inputs:
              versionSpec: '3.9'
          displayName: 'Use Python 3.9'

        - script: |
              python -m venv antenv
              source antenv/bin/activate
              python -m pip install --upgrade pip
              pip install setup
              pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
          workingDirectory: $(Build.SourcesDirectory)
          displayName: "Install requirements"

        - task: ArchiveFiles@2
          inputs:
            rootFolderOrFile: '$(Build.SourcesDirectory)'
            includeRootFolder: false
            archiveType: 'zip'
            archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
            replaceExistingArchive: true
        - task: PublishPipelineArtifact@1
          inputs:
            targetPath: '$(Build.ArtifactStagingDirectory)'
            artifactName: 'drop'
            publishLocation: 'pipeline'
          
        - task: DownloadBuildArtifacts@1
          inputs:
            buildType: 'current'
            downloadType: 'single'
            artifactName: 'drop'
            downloadPath: '$(System.ArtifactsDirectory)'
        
        - task: AzureWebApp@1
          inputs:
            azureSubscription: 'spnv-g'
            appType: 'webAppLinux'
            appName: 'helloworld-flaskpipelines'
            deployToSlotOrASE: true
            resourceGroupName: 'rg_4099'
            package: '$(System.ArtifactsDirectory)/$(Build.BuildId).zip'
            startUpCommand: 'gunicorn --bind=0.0.0.0 --workers=4 startup:app'

我对“ArchiveFiles”任务和“AzureWebApp”任务进行了更改,如提供的屏幕截图所示:
changes made in archievefile task
changes made in azurewebapp task

相关问题