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
I believe the issue is about the environment variable. You need to define it correctly. Can use this as reference
Gunicorn Environment Variable Setting
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.In addition, for app setting, you should set
SCM_DO_BUILD_DURING_DEPLOYMENT
to 1.please also check if ‘csvvalidator.validator.wsgi’ is part of your Django project, ensure that it’s correctly referenced.