error 503 while running pipeline python azure webapp
**Container logs
**
2024-08-16T13:29:57.464Z ERROR - Container webapp-dev-registry-api_0_d6d8a485 for site webapp-dev-registry-api has exited, failing site start
2024-08-16T13:29:57.493Z ERROR - Container webapp-dev-registry-api_0_d6d8a485 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2024-08-16T13:29:57.559Z INFO - Stopping site webapp-dev-registry-api because it failed during startup./home/LogFiles/2024_08_19_lw1sdlwk0006XW_default_docker.log (https://webapp-dev-registry-api.scm.azurewebsites.net/api/vfs/LogFiles/2024_08_19_lw1sdlwk0006XW_default_docker.log)
2024-08-19T09:48:20.591542291Z File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2024-08-19T09:48:20.591545691Z File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2024-08-19T09:48:20.591548991Z File "/tmp/8dcbc77b3d1cee9/app.py", line 9, in <module>
2024-08-19T09:48:20.591552391Z from azure.cosmos import CosmosClient, PartitionKey, ProxyConfiguration
2024-08-19T09:48:20.591555791Z ImportError: cannot import name 'CosmosClient' from 'azure.cosmos' (/tmp/8dcbc77b3d1cee9/antenv/lib/python3.9/site-packages/azure/cosmos/init.py)
2024-08-19T09:48:20.591568591Z [2024-08-19 09:48:20 +0000] [1074] [INFO] Worker exiting (pid: 1074)
2024-08-19T09:48:20.839185256Z [2024-08-19 09:48:20 +0000] [1071] [ERROR] Worker (pid:1074) exited with code 3
2024-08-19T09:48:20.849033126Z [2024-08-19 09:48:20 +0000] [1071] [ERROR] Shutting down: Master
2024-08-19T09:48:20.849551730Z [2024-08-19 09:48:20 +0000] [1071] [ERROR] Reason: Worker failed to boot./home/LogFiles/2024_08_19_lw1sdlwk0006XW_docker.log (https://webapp-dev-registry-api.scm.azurewebsites.net/api/vfs/LogFiles/2024_08_19_lw1sdlwk0006XW_docker.log)
2024-08-19T09:47:03.107Z INFO - Starting container for site
2024-08-19T09:47:03.107Z INFO - docker run -d --expose=8000 --name webapp-dev-registry-api_0_c12795f8 -e WEBSITE_USE_DIAGNOSTIC_SERVER=false -e WEBSITE_SITE_NAME=webapp-dev-registry-api -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=webapp-dev-registry-api.azurewebsites.net -e WEBSITE_INSTANCE_ID=b69d9c88041fe5125a840627a5b76422f886fc7a09938923c527e6effb8afe42 -e HTTP_LOGGING_ENABLED=1 appsvc/python:3.9_20240814.3.tuxprod
2024-08-19T09:47:12.547Z INFO - Initiating warmup request to container webapp-dev-registry-api_0_c12795f8 for site webapp-dev-registry-api
2024-08-19T09:47:30.962Z INFO - Waiting for response to warmup request for container webapp-dev-registry-api_0_c12795f8. Elapsed time = 18.4170048 sec
2024-08-19T09:47:51.007Z INFO - Waiting for response to warmup request for container webapp-dev-registry-api_0_c12795f8. Elapsed time = 38.4518859 sec
2024-08-19T09:48:11.580Z INFO - Waiting for response to warmup request for container webapp-dev-registry-api_0_c12795f8. Elapsed time = 59.0348972 sec
2024-08-19T09:48:22.106Z ERROR - Container webapp-dev-registry-api_0_c12795f8 for site webapp-dev-registry-api has exited, failing site start
2024-08-19T09:48:22.128Z ERROR - Container webapp-dev-registry-api_0_c12795f8 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
env variables
gitlab-ci.yml
stages:
- build
- deploy
build job:
stage: build
script:
- export PYTHONPATH=.
- export FLASK_APP=app
- apt-get update -qy
- apt-get install -y python3-setuptools python3-dev python3-pip
- pip3 install --upgrade pip
- pip3 install -r requirements.txt
- pytest tests --cov --cov-report term --cov-report html
deploy-job:
stage: deploy
image: mcr.microsoft.com/azure-cli:latest
variables:
CLIENT_ID: "<CLIENT_ID>"
TENANT_ID: "<TENANT_ID>"
SUBSCRIPTION_ID: "<SUBSCRIPTION_ID>"
id_tokens:
GITLAB_OIDC_TOKEN:
aud: https://gitlab.******.io
script:
- az cache purge
- az login --service-principal -u $CLIENT_ID -t $TENANT_ID --federated-token $GITLAB_OIDC_TOKEN
- az account show
- az webapp config appsettings set --resource-group export-control-test --name webapp-dev-registry-api --settings WEBSITES_PORT=8000
- az webapp up --runtime PYTHON:3.9 --sku B1 --logs --name webapp-dev-registry-api --location westeurope -g export-control-test
Dockerfile
# syntax=docker/dockerfile:1
FROM python:3.11
WORKDIR /code
COPY requirements.txt .
RUN apt-get install curl && curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN pip3 install -r requirements.txt
COPY . .
EXPOSE 50505
ENTRYPOINT ["gunicorn", "app:app"]
deploy.sh
gunicorn --bind=0.0.0.0:9060 --preload --daemon reload:app
gunicorn --bind 0.0.0.0:9061 --preload --chdir app:app
Dockerfile
azure-core
azure-keyvault-secrets
azure-identity
azure-mgmt-resource
azure-cli
azure-cosmos
Flask
gunicorn
Werkzeug
pymysql
pytest
pytest-cov
requests
setuptools_rust
urllib3==1.26.6
Settings > Configuration
Solutions i've tried
- upgrading plan from B1 to S1
- changin azure-cosmos version
- adding WEBSITES_PORTS to environnement variables
- expose 8000 port on Dockerfile
- checking "Diagnose and solve problems" > Availability and Performance > Webapp Troubleshooting solutions