i Just deployed a Django app from Azure Devops Pipeline to an Azure webapp, the Pipeline runs fine, but it shows an error when try access using web browse: "Application Error" .
The logs from bash shell don’t tell much neither.
The Stream logs shows that the app tries to start but then stops.
2023-10-11T19:18:15.793Z INFO - 3.10_20230810.1.tuxprod Pulling from appsvc/python
2023-10-11T19:18:16.054Z INFO - Digest: sha256:6e7907b272357dfda9a8c141b01fc30851ffc4448c6c41b81d6d6d63d2de0472
2023-10-11T19:18:16.064Z INFO - Status: Image is up to date for mcr.microsoft.com/appsvc/python:3.10_20230810.1.tuxprod
2023-10-11T19:18:16.150Z INFO - Pull Image successful, Time taken: 0 Minutes and 1 Seconds
2023-10-11T19:18:16.450Z INFO - Starting container for site
2023-10-11T19:18:16.451Z INFO - docker run -d --expose=8000 --name webapp-firma-backend_1_9d3d260f -e WEBSITES_PORT=8000 -e WEBSITE_SITE_NAME=webapp-firma-backend -e WEBSITE_AUTH_ENABLED=False -e PORT=8000 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=webapp-firma-backend.azurewebsites.net -e WEBSITE_INSTANCE_ID=0a01d13b0c74e2087a0a20c4078e93f91439134653f92861a8deef4a0aa726ab -e HTTP_LOGGING_ENABLED=1 -e WEBSITE_USE_DIAGNOSTIC_SERVER=False appsvc/python:3.10_20230810.1.tuxprod sh start.sh
2023-10-11T19:18:20.351Z INFO - Initiating warmup request to container webapp-firma-backend_1_9d3d260f for site webapp-firma-backend
2023-10-11T19:18:19.698796823Z _____
2023-10-11T19:18:19.698834524Z / _ __________ _________ ____
2023-10-11T19:18:19.698839824Z / /_ \___ / | _ __ _/ __
2023-10-11T19:18:19.698843324Z / | / /| | /| | / ___/
2023-10-11T19:18:19.698846424Z ____|__ /_____ ____/ |__| ___ >
2023-10-11T19:18:19.698849924Z / / /
2023-10-11T19:18:19.698853024Z A P P S E R V I C E O N L I N U X
2023-10-11T19:18:19.698856124Z
2023-10-11T19:18:19.698858924Z Documentation: http://aka.ms/webapp-linux
2023-10-11T19:18:19.698861924Z Python 3.10.12
2023-10-11T19:18:19.698864824Z Note: Any data outside '/home' is not persisted
2023-10-11T19:18:22.532069268Z Starting OpenBSD Secure Shell server: sshd.
2023-10-11T19:18:22.724222854Z Site's appCommandLine: sh start.sh
2023-10-11T19:18:23.140207138Z Starting periodic command scheduler: cron.
2023-10-11T19:18:23.142112251Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'sh start.sh'
2023-10-11T19:18:23.284122002Z Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2023-10-11T19:18:23.286167615Z Could not find operation ID in manifest. Generating an operation id...
2023-10-11T19:18:23.286184815Z Build Operation ID: 75f788f6-e4c1-425b-b449-7e366b73442f
2023-10-11T19:18:24.205200969Z Oryx Version: 0.2.20230707.1, Commit: 0bd28e69919b5e8beba451e8677e3345f0be8361, ReleaseTagName: 20230707.1
2023-10-11T19:18:24.260669041Z Writing output script to '/opt/startup/startup.sh'
2023-10-11T19:18:24.629063908Z Using packages from virtual environment antenv located at /home/site/wwwroot/antenv.
2023-10-11T19:18:24.629131609Z Updated PYTHONPATH to '/opt/startup/app_logs:/home/site/wwwroot/antenv/lib/python3.10/site-packages'
2023-10-11T19:18:24.647941435Z Firmas app is running
2023-10-11T19:18:35.785Z ERROR - Container webapp-firma-backend_1_9d3d260f for site webapp-firma-backend has exited, failing site start
2023-10-11T19:18:35.853Z ERROR - Container webapp-firma-backend_1_9d3d260f didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2023-10-11T19:18:35.892Z INFO - Stopping site webapp-firma-backend because it failed during startup.
The startup command (start.sh file) includes also celery command:
# Start with runserver
echo "---------------------> Starting Firmas app"
python3 -m celery -A firma worker &
echo "---------------------> Celery is running"
echo "---------------------> Starting Firmas app"
python3 manage.py runserver 127.0.0.1:8000 --settings=firma.settings.staging &
What i need to check to identify what needs to be fixed.
UPDATE:
I worked on the pipeline, create a new webapp, deploy to it and got an error that cannot find the virtualenv on /home/site/wwwroot neither the start.sh file, in fact there’s nothing about the project there.
In app configuration I have the SCM_DO_BUILD_DURING_DEPLOYMENT in true
My pipeline now is:
trigger:
- staging
pool:
name: MyPool
jobs:
- job: Build_Deploy_Jobs
timeoutInMinutes: 0
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.10'
architecture: 'x64'
displayName: 'Install Python3'
- task: DownloadSecureFile@1
inputs:
secureFile: '.env'
- task: CopyFiles@2
inputs:
SourceFolder: $(Agent.TempDirectory)
Contents: '**.env'
TargetFolder: $(System.DefaultWorkingDirectory)
# Archive Django project and save it as a build artifact
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/Application$(Build.BuildId).zip'
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/Application$(Build.BuildId).zip
displayName: 'Upload package'
artifact: drop
# Deploy to Azure App Service using zip deploy
- task: AzureWebApp@1
inputs:
azureSubscription: 'MyAzureSubscription'
appType: 'webAppLinux'
AppName: 'webapp-firma-backend'
ResourceGroupName: 'my_group_resource'
# packageForLinux: '$(System.DefaultWorkingDirectory)/drop/Application$(Build.BuildId).zip'
package: '$(Build.ArtifactStagingDirectory)/Application$(Build.BuildId).zip'
deploymentMethod: 'zipDeploy'
RuntimeStack: 'PYTHON|3.10'
StartupCommand: 'sh start.sh'
displayName: 'Deploy to Azure Web App'
UPDATE:
Also tried to start the app from azure shell and the output is this.
2023-10-19T16:09:09.975Z INFO - Initiating warmup request to container webapp-firma-backend_1_ea2e7a52 for site webapp-firma-backend
2023-10-19T16:09:43.438Z INFO - Waiting for response to warmup request for container webapp-firma-backend_1_ea2e7a52. Elapsed time = 33.4640904 sec
2023-10-19T16:09:08.708425925Z _____
2023-10-19T16:09:08.708490937Z / _ __________ _________ ____
2023-10-19T16:09:08.708497638Z / /_ \___ / | _ __ _/ __
2023-10-19T16:09:08.708502038Z / | / /| | /| | / ___/
2023-10-19T16:09:08.708506139Z ____|__ /_____ ____/ |__| ___ >
2023-10-19T16:09:08.708510740Z / / /
2023-10-19T16:09:08.708514941Z A P P S E R V I C E O N L I N U X
2023-10-19T16:09:08.708518841Z
2023-10-19T16:09:08.708522642Z Documentation: http://aka.ms/webapp-linux
2023-10-19T16:09:08.708526643Z Python 3.10.12
2023-10-19T16:09:08.708530543Z Note: Any data outside '/home' is not persisted
2023-10-19T16:09:10.881679007Z Starting OpenBSD Secure Shell server: sshd.
2023-10-19T16:09:11.001450410Z Site's appCommandLine: sh start.sh
2023-10-19T16:09:11.258576570Z Starting periodic command scheduler: cron.
2023-10-19T16:09:11.258637180Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'sh start.sh'
2023-10-19T16:09:11.352948161Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2023-10-19T16:09:11.354821486Z Build Operation ID: b9d4a69afdf78a56
2023-10-19T16:09:11.356005592Z Output is compressed. Extracting it...
2023-10-19T16:09:11.356034497Z Oryx Version: 0.2.20230707.1, Commit: 0bd28e69919b5e8beba451e8677e3345f0be8361, ReleaseTagName: 20230707.1
2023-10-19T16:09:11.385348488Z Extracting '/home/site/wwwroot/output.tar.gz' to directory '/tmp/8dbd0bcfc71f249'...
2023-10-19T16:09:20.229883014Z App path is set to '/tmp/8dbd0bcfc71f249'
2023-10-19T16:09:20.438765316Z Writing output script to '/opt/startup/startup.sh'
2023-10-19T16:09:20.644181121Z Using packages from virtual environment antenv located at /tmp/8dbd0bcfc71f249/antenv.
2023-10-19T16:09:20.644218328Z Updated PYTHONPATH to '/opt/startup/app_logs:/tmp/8dbd0bcfc71f249/antenv/lib/python3.10/site-packages'
2023-10-19T16:09:20.661278660Z Collect static
2023-10-19T16:09:27.525451013Z
2023-10-19T16:09:27.525516625Z 0 static files copied to '/tmp/8dbd0bcfc71f249/static', 160 unmodified.
2023-10-19T16:09:28.048318675Z ------------------------->Start migratons
2023-10-19T16:09:37.245828918Z No changes detected
2023-10-19T16:09:42.834036937Z Operations to perform:
2023-10-19T16:09:42.834109249Z Apply all migrations: admin, auth, contenttypes, documents, employees, oauth2_provider, sessions, users
2023-10-19T16:09:42.834117350Z Running migrations:
2023-10-19T16:09:42.834122451Z No migrations to apply.
2023-10-19T16:09:43.864763198Z ---------------------> Starting Firmas app
2023-10-19T16:09:43.866405463Z ---------------------> Celery is running
2023-10-19T16:09:43.873497505Z ---------------------> Starting Firmas app
2023-10-19T16:09:44.520Z ERROR - Container webapp-firma-backend_1_ea2e7a52 for site webapp-firma-backend has exited, failing site start
2023-10-19T16:09:44.719Z ERROR - Container webapp-firma-backend_1_ea2e7a52 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
My start script has the echo messages.
The runserver command fails, i could not figure it out what is the issue there.
2
Answers
Following @andy-li-msft suggestion, I deployed manually and get that at startup django try to get enviroment vars (even having .env file), so, i added the vars in: Settings > Configuration
Then the app started fine.
Per the logs, it fails to respond to HTTP pings on port 8000. This could be caused by incorrect configuration settings or issues with the container image.
Basically, App Service will listen on port 80 and forward traffic to your container. If your container listens on another port (ex: 8000 in your scenario), you can try to set the
WEBSITES_PORT
application setting to that port number.So, please try below options to see if that helps:
1.Expose port to 8000 in your Docker file like below:
2.Check the container logs to figure out the errors or issues which is causing the container to fail in App Service -> Deployment Center -> Logs tab.
3.Add a new Application Settings under Configuration for
WEBSITES_PORT
orPORT
equal to the port your app is listening on, which is port8000
in your scenario:Just go to App Service -> Configuration -> Application settings -> set the configuration.
or
Restart your App Service after configuring the
WEBSITES_PORT
orPORT
setting to the same port that your application is listening to.Then redeploy the app from pipeline to check the result.
UPDATE:
According to Juan’s feedback, the same issue exists when deploying manually. Confirm that it’s an app settings issue. It works fine after adding the corresponding settings.