503 error on pipeline while deploying webapp (unit test step)

Sara CAVALCANTE-LIMA 0 Reputation points
2024-08-19T10:16:02.69+00:00

error 503 while running pipeline python azure webapp

25560-image.png

**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

User's image

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

User's image

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
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Deployment: The process of delivering, assembling, and maintaining a particular version of a software system at a site.
990 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,893 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 26,471 Reputation points Microsoft Employee
    2024-08-20T11:06:37.69+00:00

    Sara CAVALCANTE-LIMA, I see that you have tried multiple steps to isolate the issue.

    Based on my understanding of your issue description, I'm sharing list of possible causes ( A- I) for this error.

    ( sorry for the long post, just highlighting all the reason to help you isolate the issue, I understand you have tried some of these, please review them)

    Firstly, by default, if your container does not respond after 230 seconds, it will time out. (This time out can be increased by with the WEBSITES_CONTAINER_START_TIME_LIMIT app setting.) (up to a maximum of 1800).

    Possible causes for the error: ‘Container didnt respond to HTTP pings on port, failing site start’.

    A. Incorrect port values : Need to update the application code to listen to correct port.

    B. Binding to localhost : Applications deployed to App Service Linux should not be attempting to bind to localhost or 127.0.0.1.

    C. Long application startup routines and logic: Applications that have a very long startup time before an HTTP response is sent back may encounter this error.

    D. Development Servers: It is not recommended to use these in production, and rather use the appropriate production server equivalent.

    E. Key Vault dependencies: Some applications call to Key Vault to retrieve secrets on startup. If this call fails (eg., application is an unauthorized caller on Key Vault) - then the value, such as a secret or connection string will not be retrieved.

    F: Root route is not configured to return an HTTP response: In some scenarios, an application may actually not be developed to return an HTTP response on the root (/) path. Although rare, it is best to ensure an actual HTTP status code is returned.

    G. Missing Environment Variables: Some applications depend on environment variables for certain environments. On App Service, these are added via the App Settings functionality, which is essentially environment variables.

    H. Incorrect startup commands: Applications that use certain startup commands depending on their environment may encounter this behavior.

    I. Installing packages on startup: Depending on the package size - and number of packages - this may introduce extended startup time in these scenarios.

    Reference : See this doc for more detailed steps: Troubleshooting ‘Container didnt respond to HTTP pings on port, failing site start’

    Kindly let us know, I'll follow-up with you further.


    To benefit the community, please click Accept Answer - it will help community find the answers quicker.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.