skip to Main Content

I am facing an issue with deploying a Django application on Azure Web App Linux using Gunicorn. The deployment process appears to be successful, but the Gunicorn worker fails to boot with the following error:

[2024-03-07 04:42:30 +0000] [71] [ERROR] Exception in worker process
...
ModuleNotFoundError: No module named 'csvvalidator.validator.wsgi'
...

csvvalidator is the project directory and validator is the app name. This is all my YAML file:

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.10'
    addToPath: true

- script: |
    python -m venv antenv
    source antenv/bin/activate
    pip install -r requirements.txt
  displayName: 'Install dependencies'

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

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    artifactName: 'drop'
    publishLocation: 'Container'

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'drop'
    downloadPath: '$(System.ArtifactStagingDirectory)'

- task: AzureRmWebAppDeployment@4
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'Subscription'
    appType: 'webAppLinux'
    WebAppName: 'safe-lives-copilot-dev'
    packageForLinux: '$(System.ArtifactStagingDirectory)/**/*.zip'
    RuntimeStack: 'PYTHON|3.10'
    StartupCommand: '. antenv/bin/activate && gunicorn -b :8000 csvvalidator.validator.wsgi:application'

Any guidance or insights on resolving this Gunicorn worker boot failure would be highly appreciated.

2

Answers


  1. I believe the issue is about the environment variable. You need to define it correctly. Can use this as reference

    Gunicorn Environment Variable Setting

    Login or Signup to reply.
  2. As per the doc ModuleNotFoundError when app starts, this error most often occurs if you deploy your virtual environment with your code. Virtual environment shouldn’t be deployed with your application code.

    You could exclude !venv/** from your zip file.

    - task: CopyFiles@2
      inputs:
        Contents: |
          $(Build.Repository.LocalPath)/**
          !venv/**
          !.git/**
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
    
    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: |
          $(Build.ArtifactStagingDirectory)
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true
    

    In addition, for app setting, you should set SCM_DO_BUILD_DURING_DEPLOYMENTto 1.

    please also check if ‘csvvalidator.validator.wsgi’ is part of your Django project, ensure that it’s correctly referenced.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search