I have an appservice running on Azure in a Linux environment.
I try to associate it with a Azure Devops Pipeline so I can have CI/CD for the repositories & branches on Github.
I want the builds to occur on Azure Pipeline & Azure infrastructure, not Github Actions.
I have tried all other suggestions including following environment variables on App Service :
SCM_DO_BUILD_DURING_DEPLOYMENT=true
WEBSITE_NODE_DEFAULT_VERSION=~18
WEBSITE_RUN_FROM_PACKAGE=true
Here is the logs that I receive from the Kudu / Azure Devops Pipeline / AppService logs :
/home/LogFiles/2024_08_14_ln1xsdlwk0000K3_docker.log (https://project-app-development.scm.azurewebsites.net/api/vfs/LogFiles/2024_08_14_ln1xsdlwk0000K3_docker.log)
2024-08-14T23:51:45.168Z INFO - Status: Image is up to date for 10.1.0.6:13209/appsvc/python:3.10_20240619.2.tuxprod
2024-08-14T23:51:45.179Z INFO - Pull Image successful, Time taken: 0 Seconds
2024-08-14T23:51:45.223Z INFO - Starting container for site
2024-08-14T23:51:45.223Z INFO - docker run -d --expose=8000 --name project-app-development_0_f2e0544d -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e WEBSITE_SITE_NAME=project-app-development -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=project-app-development.azurewebsites.net -e WEBSITE_INSTANCE_ID=3f627dbbecdaed255d87aa9c3e8f1448758df1cdff41f5e14b114384ea9b244a appsvc/python:3.10_20240619.2.tuxprod gunicorn -b :$PORT project.wsgi
2024-08-14T23:51:45.223Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2024-08-14T23:51:45.893Z INFO - Initiating warmup request to container project-app-development_0_f2e0544d for site project-app-development
2024-08-14T23:51:49.043Z ERROR - Container project-app-development_0_f2e0544d for site project-app-development has exited, failing site start
2024-08-14T23:51:49.057Z ERROR - Container project-app-development_0_f2e0544d didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2024-08-14T23:51:49.063Z INFO - Stopping site project-app-development because it failed during startup.
/home/LogFiles/2024_08_14_ln1xsdlwk0000WT_default_docker.log (https://project-app-development.scm.azurewebsites.net/api/vfs/LogFiles/2024_08_14_ln1xsdlwk0000WT_default_docker.log)
2024-08-14T00:05:39.611783454Z File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2024-08-14T00:05:39.611788754Z File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2024-08-14T00:05:39.611793955Z File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2024-08-14T00:05:39.611799355Z File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
2024-08-14T00:05:39.611804655Z ModuleNotFoundError: No module named 'project'
2024-08-14T00:05:39.611810055Z [2024-08-14 00:05:39 +0000] [83] [INFO] Worker exiting (pid: 83)
2024-08-14T00:05:39.756375163Z [2024-08-14 00:05:39 +0000] [49] [ERROR] Worker (pid:83) exited with code 3
2024-08-14T00:05:39.758705055Z [2024-08-14 00:05:39 +0000] [49] [ERROR] Shutting down: Master
2024-08-14T00:05:39.758726256Z [2024-08-14 00:05:39 +0000] [49] [ERROR] Reason: Worker failed to boot.
Here is my startup command on Azure AppService Configuration :
gunicorn -b :8000 project.wsgi
% cat app.yaml
runtime: python37
entrypoint: gunicorn -b :$PORT project.wsgi
# service: "project-ai-266410"
service: "default"
handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
static_dir: static
secure: always
# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
script: auto
secure: always%
% cat ./project/wsgi.py
"""
WSGI config for project project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
Here is my github workflow file :
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
name: Build and deploy Python app to Azure Web App - project-app-development
on:
push:
branches:
- 543-azure-based-secrets
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python version
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Create and start virtual environment
run: |
python -m venv antenv
source antenv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
- name: Zip artifact for deployment
run: zip release.zip ./* -r
- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v4
with:
name: python-app
path: |
release.zip
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
id-token: write #This is required for requesting the JWT
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: python-app
- name: Unzip artifact for deployment
run: unzip release.zip
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5DF5B8B04E0349C7828DF5D5B258B9CD }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_741E597FD19043F4B2CBF83B89C75D92 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_ED0C3DE592084669926EEBA461FB5E98 }}
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v3
id: deploy-to-webapp
with:
app-name: 'project-app-development'
slot-name: 'Production'
Azure devops Yaml file :
trigger:
- $(feature-branch)
variables:
azureServiceConnectionId: '-db5f-4993-91f8-85f3a75cb357'
webAppName: 'project-app-development'
vmImageName: 'ubuntu-latest'
environmentName: 'project-app-development'
projectRoot: $(System.DefaultWorkingDirectory)
pythonVersion: '3.8'
system.debug: true
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 virtualenv env
source env/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
workingDirectory: $(projectRoot)
displayName: "Install requirements"
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(projectRoot)'
includeRootFolder: true
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 : project-app-development'
inputs:
azureSubscription: $(azureServiceConnectionId)
appName: $(webAppName)
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
Latest github actions error message :
##[debug]logs from kudu deploy: https://project-app-development.scm.azurewebsites.net/api/deployments/temp-69fc3536/log
##[debug]setting affinity cookie ["ARRAffinity=f1c95587fdc6f942a20e5a5078e78322a753dff56e2f30cc9c09a2b930fa89ac;Path=/;HttpOnly;Secure;Domain=project-app-development.scm.azurewebsites.net","ARRAffinitySameSite=f1c95587fdc6f942a20e5a5078e78322a753dff56e2f30cc9c09a2b930fa89ac;Path=/;HttpOnly;SameSite=None;Secure;Domain=project-app-development.scm.azurewebsites.net"]
##[debug][GET] https://project-app-development.scm.azurewebsites.net/api/deployments/temp-69fc3536/log
##[debug]getDeploymentLogs. Data: {"statusCode":200,"statusMessage":"OK","headers":{"content-length":"268","content-type":"application/json; charset=utf-8","date":"Mon, 19 Aug 2024 15:57:25 GMT","server":"Kestrel"},"body":[{"log_time":"2024-08-19T15:57:13.2195847Z","id":"afc2dd47-e1ad-4b07-b6aa-fb59b6531aad","message":"Fetching changes.","type":0,"details_url":"https://project-app-development.scm.azurewebsites.net/api/deployments/temp-69fc3536/log/afc2dd47-e1ad-4b07-b6aa-fb59b6531aad"}]}
Fetching changes.
##[debug]setting affinity cookie ["ARRAffinity=f1c95587fdc6f942a20e5a5078e78322a753dff56e2f30cc9c09a2b930fa89ac;Path=/;HttpOnly;Secure;Domain=project-app-development.scm.azurewebsites.net","ARRAffinitySameSite=f1c95587fdc6f942a20e5a5078e78322a753dff56e2f30cc9c09a2b930fa89ac;Path=/;HttpOnly;SameSite=None;Secure;Domain=project-app-development.scm.azurewebsites.net"]
##[debug][GET] https://project-app-development.scm.azurewebsites.net/api/deployments/temp-69fc3536/log/afc2dd47-e1ad-4b07-b6aa-fb59b6531aad
##[debug]getDeploymentLogs. Data: {"statusCode":200,"statusMessage":"OK","headers":{"content-length":"274","content-type":"application/json; charset=utf-8","date":"Mon, 19 Aug 2024 15:57:26 GMT","server":"Kestrel"},"body":[{"log_time":"2024-08-19T15:57:14.2281682Z","id":"","message":"Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/c28a10f3-d998-437f-94af-eed376d90b90.zip (24.85 MB) to /tmp/zipdeploy/extracted","type":0,"details_url":null}]}
Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/c28a10f3-d998-437f-94af-eed376d90b90.zip (24.85 MB) to /tmp/zipdeploy/extracted
Error: Failed to deploy web package to App Service.
Error: Deployment Failed, Package deployment using ZIP Deploy failed. Refer logs for more details.
##[debug][POST] https://management.azure.com/subscriptions/***/resourceGroups/project-app-development_group/providers/Microsoft.Web/sites/project-app-development/config/appsettings/list?api-version=2016-08-01
##[debug][GET] https://management.azure.com/subscriptions/***/providers/microsoft.insights/components?$filter=InstrumentationKey eq '4f576d13-00e5-4831-a1d5-7e5ea3cab3c5'&api-version=2015-05-01
##[debug]Unable to find Application Insights resource with Instrumentation key 4f576d13-00e5-4831-a1d5-7e5ea3cab3c5. Skipping adding release annotation.
App Service Application URL: https://project-app-development.azurewebsites.net
##[debug]Deployment failed
##[debug]Node Action run completed with exit code 1
##[debug]AZURE_HTTP_USER_AGENT='GITHUBACTIONS_DeployWebAppToAzure_0a886200850ef7f915637c263559bb1d8963ef779ce24674d123a365c5ec1237'
##[debug]AZURE_HTTP_USER_AGENT=''
##[debug]Set output webapp-url = https://project-app-development.azurewebsites.net
##[debug]Finishing: Deploy to Azure Web App
Simpler error logs (Turned off advanced logs)
Run azure/webapps-deploy@v3
Package deployment using OneDeploy initiated.
{
id: 'temp-fb83a24b',
status: 3,
status_text: '',
author_email: 'N/A',
author: 'N/A',
deployer: 'OneDeploy',
message: 'OneDeploy',
progress: '',
received_time: '2024-08-19T16:47:42.3127586Z',
start_time: '2024-08-19T16:47:42.3127586Z',
end_time: '2024-08-19T16:47:51.8169497Z',
last_success_end_time: null,
complete: true,
active: false,
is_temp: true,
is_readonly: false,
url: 'https://project-app-development.scm.azurewebsites.net/api/deployments/temp-fb83a24b',
log_url: 'https://project-app-development.scm.azurewebsites.net/api/deployments/temp-fb83a24b/log',
site_name: 'project-app-development',
build_summary: { errors: [], warnings: [] }
}
Fetching changes.
Cleaning up temp folders from previous zip deployments and extracting pushed zip file /tmp/zipdeploy/31a79a90-85fe-4021-92a0-24cd5f24118d.zip (24.85 MB) to /tmp/zipdeploy/extracted
Error: Failed to deploy web package to App Service.
Error: Deployment Failed, Package deployment using ZIP Deploy failed. Refer logs for more details.
App Service Application URL: https://project-app-development.azurewebsites.net
When I set includeRootFolder : true, build does not fail, logs : succesful but not working detailed logs 488
When I set includeRootFolder : false, build fails with the following, you can find the detailed logs here : failed detailed logs 489
Update : I am also trying with Github actions, the primary problem is : the zip file never arrives to Appservice from devops; either azure pipelines or github actions.
Change diff for "includeRootFolder : false" :
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(projectRoot)'
includeRootFolder: true
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
Logs after setting "includeRootFolder : false" :
##[error]Failed to deploy web package to App Service.
##[error]KuduStackTraceURL https://$project-app-development:***@videoo-app-development.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace
##[error]Error: Package deployment using ZIP Deploy failed. Refer logs for more details.
Latest logs after setting
-includeRootFolder : false
-ENABLE_ORYX_BUILD : false
-SCM_DO_BUILD_DURING_DEPLOYMENT : true
-WEBSITE_RUN_FROM_PACKAGE : 1
2024-08-20T05:57:34.254Z INFO - Starting container for site
2024-08-20T05:57:34.256Z INFO - docker run -d --expose=8000 --name project-app-development_0_c5c7b0dd -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e PORT=8000 -e WEBSITES_PORT=8000 -e WEBSITE_SITE_NAME=project-app-development -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=project-app-development.azurewebsites.net -e WEBSITE_INSTANCE_ID=3f627dbbecdaed255d87aa9c3e8f1448758df1cdff41f5e14b114384ea9b244a -e HTTP_LOGGING_ENABLED=1 appsvc/python:3.8-bullseye_20240619.2.tuxprod
2024-08-20T05:57:35.308Z INFO - Initiating warmup request to container project-app-development_0_c5c7b0dd for site project-app-development
2024-08-20T05:57:36.327Z ERROR - Container project-app-development_0_c5c7b0dd for site project-app-development has exited, failing site start
2024-08-20T05:57:36.334Z ERROR - Container project-app-development_0_c5c7b0dd didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2024-08-20T05:57:36.337Z INFO - Stopping site project-app-development because it failed during startup.
2024-08-20T05:57:53.915425573Z _____
2024-08-20T05:57:53.915485375Z / _ \ __________ _________ ____
2024-08-20T05:57:53.915492475Z / /_\ \\___ / | \_ __ \_/ __ \
2024-08-20T05:57:53.915497675Z / | \/ /| | /| | \/\ ___/
2024-08-20T05:57:53.915502375Z \____|__ /_____ \____/ |__| \___ >
2024-08-20T05:57:53.915507176Z \/ \/ \/
2024-08-20T05:57:53.915511976Z A P P S E R V I C E O N L I N U X
2024-08-20T05:57:53.915516676Z
2024-08-20T05:57:53.915521376Z Documentation: http://aka.ms/webapp-linux
2024-08-20T05:57:53.915529576Z Python 3.8.19
2024-08-20T05:57:53.915536477Z Note: Any data outside '/home' is not persisted
2024-08-20T05:57:54.221285535Z Starting OpenBSD Secure Shell server: sshd.
2024-08-20T05:57:54.235160933Z WEBSITES_INCLUDE_CLOUD_CERTS is not set to true.
2024-08-20T05:57:54.265297413Z App Command Line not configured, will attempt auto-detect
2024-08-20T05:57:54.265793631Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite
2024-08-20T05:57:54.292483387Z Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2024-08-20T05:57:54.292508088Z Could not find operation ID in manifest. Generating an operation id...
2024-08-20T05:57:54.292513388Z Build Operation ID: b6e4f53f-a160-4836-81df-40a78959b714
2024-08-20T05:57:54.395411376Z Oryx Version: 0.2.20240619.2, Commit: cf006407a02b225f59dccd677986973c7889aa50, ReleaseTagName: 20240619.2
2024-08-20T05:57:54.398960704Z Detected an app based on Django
2024-08-20T05:57:54.399159411Z Generating `gunicorn` command for 'project.wsgi'
2024-08-20T05:57:54.410518018Z Writing output script to '/opt/startup/startup.sh'
2024-08-20T05:57:54.427810538Z WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
2024-08-20T05:57:54.427831338Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.
2024-08-20T05:57:54.970237380Z [2024-08-20 05:57:54 +0000] [48] [INFO] Starting gunicorn 22.0.0
2024-08-20T05:57:54.987807809Z [2024-08-20 05:57:54 +0000] [48] [INFO] Listening at: http://0.0.0.0:8000 (48)
2024-08-20T05:57:54.987844111Z [2024-08-20 05:57:54 +0000] [48] [INFO] Using worker: sync
2024-08-20T05:57:54.997822968Z [2024-08-20 05:57:54 +0000] [57] [INFO] Booting worker with pid: 57
2024-08-20T05:57:55.045597781Z [2024-08-20 05:57:55 +0000] [57] [ERROR] Exception in worker process
2024-08-20T05:57:55.045636382Z Traceback (most recent call last):
2024-08-20T05:57:55.045643782Z File "/opt/python/3.8.19/lib/python3.8/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
2024-08-20T05:57:55.045658983Z worker.init_process()
2024-08-20T05:57:55.045664583Z File "/opt/python/3.8.19/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2024-08-20T05:57:55.045683084Z self.load_wsgi()
2024-08-20T05:57:55.045688584Z File "/opt/python/3.8.19/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2024-08-20T05:57:55.045694184Z self.wsgi = self.app.wsgi()
2024-08-20T05:57:55.045699484Z File "/opt/python/3.8.19/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2024-08-20T05:57:55.045704784Z self.callable = self.load()
2024-08-20T05:57:55.045710085Z File "/opt/python/3.8.19/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2024-08-20T05:57:55.045715485Z return self.load_wsgiapp()
2024-08-20T05:57:55.045720885Z File "/opt/python/3.8.19/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2024-08-20T05:57:55.045726285Z return util.import_app(self.app_uri)
2024-08-20T05:57:55.045731885Z File "/opt/python/3.8.19/lib/python3.8/site-packages/gunicorn/util.py", line 371, in import_app
2024-08-20T05:57:55.045737786Z mod = importlib.import_module(module)
2024-08-20T05:57:55.045743086Z File "/opt/python/3.8.19/lib/python3.8/importlib/__init__.py", line 127, in import_module
2024-08-20T05:57:55.045748486Z return _bootstrap._gcd_import(name[level:], package, level)
2024-08-20T05:57:55.045753786Z File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2024-08-20T05:57:55.045759786Z File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2024-08-20T05:57:55.045765487Z File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2024-08-20T05:57:55.045771387Z File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2024-08-20T05:57:55.045776787Z File "<frozen importlib._bootstrap_external>", line 843, in exec_module
2024-08-20T05:57:55.045782087Z File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2024-08-20T05:57:55.045787187Z File "/home/site/wwwroot/project/wsgi.py", line 12, in <module>
2024-08-20T05:57:55.045792588Z from django.core.wsgi import get_wsgi_application
2024-08-20T05:57:55.045797988Z ModuleNotFoundError: No module named 'django'
2024-08-20T05:57:55.046148100Z [2024-08-20 05:57:55 +0000] [57] [INFO] Worker exiting (pid: 57)
2024-08-20T05:57:55.107735008Z [2024-08-20 05:57:55 +0000] [48] [ERROR] Worker (pid:57) exited with code 3
2024-08-20T05:57:55.107770709Z [2024-08-20 05:57:55 +0000] [48] [ERROR] Shutting down: Master
2024-08-20T05:57:55.107777009Z [2024-08-20 05:57:55 +0000] [48] [ERROR] Reason: Worker failed to boot.
2024-08-20 05:57:54,978 [MainThread] [DEBUG] : Initializating AppServiceAppLogging
2024-08-20 05:57:54,982 [Thread-1 ] [DEBUG] : Did not find any previously bound socket
2024-08-20 05:57:54,983 [MainThread] [DEBUG] : Initialized AppServiceAppLogging
2024-08-20T05:57:53.623Z INFO - Starting container for site
2024-08-20T05:57:53.641Z INFO - docker run -d --expose=8000 --name project-app-development_0_4c6a7e4b -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e PORT=8000 -e WEBSITES_PORT=8000 -e WEBSITE_SITE_NAME=project-app-development -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=project-app-development.azurewebsites.net -e WEBSITE_INSTANCE_ID=8a9506920697ea08e988fb00cb7a286fb2bda894a9cbfd61c5690d00f38d01a6 -e HTTP_LOGGING_ENABLED=1 appsvc/python:3.8-bullseye_20240619.2.tuxprod
2024-08-20T05:57:55.010Z INFO - Initiating warmup request to container project-app-development_0_4c6a7e4b for site project-app-development
2024-08-20T05:57:56.129Z ERROR - Container project-app-development_0_4c6a7e4b for site project-app-development has exited, failing site start
2024-08-20T05:57:56.140Z ERROR - Container project-app-development_0_4c6a7e4b didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2024-08-20T05:57:56.145Z INFO - Stopping site project-app-development because it failed during startup.
I have checked your Azure DevOps YAML Pipeline sample. It has some issues which will lead to the App service not able to work.
From the original log, it shows the error: ModuleNotFoundError: No module named 'project'
. The cause of the issue is that the zip package doesn't contain the required python packages.
You can make the following changes to the Azure Pipeline YAML Sample:
1.You need to change the command to install python packages:
From
pip install -r requirements.txt
To
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
In this case, the required packages will be installed to the correct folder and will be added to the zip pacakge.
2.You need to set the includeRootFolder field to false in ArchiveFiles@2 task.
If the value is set to true, it will include the parent folder : s
to the zip package. This will cause the path issue in Web App. So we need to set the value to false.
Here is an example:
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
Full Pipeline YAML sample:
trigger:
- $(feature-branch)
variables:
azureServiceConnectionId: '-db5f-4993-91f8-85f3a75cb357'
webAppName: 'project-app-development'
vmImageName: 'ubuntu-latest'
environmentName: 'project-app-development'
projectRoot: $(System.DefaultWorkingDirectory)
pythonVersion: '3.8'
system.debug: true
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 virtualenv env
source env/bin/activate
python -m pip install --upgrade pip
pip install --target="./.python_packages/lib/site-packages" -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 : project-app-development'
inputs:
azureSubscription: $(azureServiceConnectionId)
appName: $(webAppName)
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
For more detailed info, you can refer to this doc: Use Azure Pipelines to build and deploy a Python web app to Azure App Service
Update:
Error: Package deployment using ZIP Deploy failed. Refer logs for more details.
Based on the error message, you can try the following methods:
1.Navigate to the App Settings in Azure Web App and set the variable: WEBSITE_RUN_FROM_PACKAGE
to 1
.
2.Navigate to App service --> Deployment Center, and click on the Disconnect button to disconnect the exist connections.
For example:
Then you can deploy the Azure Web App again and check the result.
Update1:
ModuleNotFoundError: No module named 'django'
I can reproduce the same issue in my Linux Web App.
To solve this issue, you can refer to the following steps:
Step1: Remove the variable: SCM_DO_BUILD_DURING_DEPLOYMENT
in AppSettings of Azure Web App. In this case, it will directly used the existing packages in the zip package.
Step2: Change the pip install command:
From:
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
To:
pip install --target="./antenv/lib/python3.8/site-packages" -r ./requirements.txt
YAML Sample:
- script: |
python -m venv antenv
source antenv/bin/activate
python -m pip install --upgrade pip
pip install setup
pip install --target="./antenv/lib/python3.9/site-packages" -r ./requirements.txt
workingDirectory: $(projectRoot)
displayName: "Install requirements"
From the log in the Azure App service, the default Python Path: /home/site/wwwroot/antenv/lib/python3.8.9/site-packages
. We need to adjust the path in the package to meet the default Python Path.
Then you can run the pipeline to deploy the web app again.