Search code examples
pythonazureazure-web-app-servicestreamlit

Azure App Service unable to deploy Streamlit app


I have a Streamlit app I am trying to deply on a B1 Azure Web App instance.

I used this tutorial as a reference: https://benalexkeen.com/deploying-streamlit-applications-with-azure-app-services/

I am pushing a zip deployment and looking through the oryx logs under deployment center I can confirm it pip installs everything in my requirements.txt without warnings or errors. SCM_DO_BUILD_DURING_DEPLOYMENT is set to true

My startup command python -m streamlit run app.py--server.port 8000 --server.address 0.0.0.0 I have also tried python -m streamlit hello --server.port 8000 --server.address 0.0.0.0 just to see if I can get Streamlit's hello world example to work.

However, in the deployment log stream:

Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.
/opt/python/3/bin/python: No module named streamlit

Docker is not an option for me to use. It has to be via zip. Some other packages I have installed/I am using that might be relevant: Transformers, BERTopic, Sentence-Transformers

I've done what I can locally to confirm the requirements.txt and startup commands work. I've also stopped, and restarted the app instance, and reuploaded the deployment zip.


Solution

  • This error is happening while importing bertopic dependency, As bertopic dependency requires C++ Microsoft Visual Studio code build tools installed and Python 3.7, Refer here. But unfortunately Streamlit app only supports Python 3.10 with B1 SKU which does not support bertopic pip package. Refer my answer here. which gives steps and pre-requisite that are needed to be followed to deploy streamlit app via github actions workflow.

    enter image description here

    enter image description here

    python -m streamlit run app.py --server.port 8000 --server.address 0.0.0.0
    

    My deployment got successful, via VS code in the above app after removing bertopic dependency like below:-

    enter image description here

    I also tried deploying the streamlit app via Azure devops pipeline like below:-

    My Devops pipeline:-

    trigger:
    - main
    
    variables:
      
      azureServiceConnectionId: 'xxxx-xxx-bxx-018f5xxx97a2'
    
      
      webAppName: 'valleywebapp09'
    
      
      vmImageName: 'ubuntu-latest'
    
      
      environmentName: 'valleywebapp09'
    
     
      projectRoot: $(System.DefaultWorkingDirectory)
    
     
      pythonVersion: '3.10'
    
    stages:
    - stage: Build
      displayName: Build stage
      jobs:
      - job: BuildJob
        pool:
          vmImage: $(vmImageName)
        steps:
        - task: UsePythonVersion@0
          inputs:
            versionSpec: '$(pythonVersion)'
          displayName: 'Use Python $(pythonVersion)'
    
        - script: |
            python -m venv antenv
            source antenv/bin/activate
            python -m pip install --upgrade pip
            pip install setup
            pip install -r requirements.txt
          workingDirectory: $(projectRoot)
          displayName: "Install requirements"
    
        - task: ArchiveFiles@2
          displayName: 'Archive files'
          inputs:
            rootFolderOrFile: '$(projectRoot)'
            includeRootFolder: false
            archiveType: zip
            archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
            replaceExistingArchive: true
    
        - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
          displayName: 'Upload package'
          artifact: drop
    
    - stage: Deploy
      displayName: 'Deploy Web App'
      dependsOn: Build
      condition: succeeded()
      jobs:
      - deployment: DeploymentJob
        pool:
          vmImage: $(vmImageName)
        environment: $(environmentName)
        strategy:
          runOnce:
            deploy:
              steps:
    
              - task: UsePythonVersion@0
                inputs:
                  versionSpec: '$(pythonVersion)'
                displayName: 'Use Python version'
    
              - task: AzureWebApp@1
                displayName: 'Deploy Azure Web App : valleywebapp09'
                inputs:
                  azureSubscription: $(azureServiceConnectionId)
                  appName: $(webAppName)
                  package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
    

    enter image description here