microsoft / sample-app-aoai-chatGPT

Sample code for a simple web chat experience through Azure OpenAI, including Azure OpenAI On Your Data.
MIT License
1.65k stars 2.6k forks source link

Using docker image and running on Azure App Service fails due to gunicorn (missing package and specific port) #602

Closed nrobert closed 2 weeks ago

nrobert commented 9 months ago

Describe the bug I'm using the project with a basic implementation: Docker image built and pushed to Azure Container Registry, and Web app using this image. I've already used it in the past with success and this issue is new from last Friday's changes made to sue async in backend, especially this one: https://github.com/microsoft/sample-app-aoai-chatGPT/commit/28f962cd659a8a05b2bbb3e4ddf356ff521a1c30#diff-939de85f28dfc44a0fa2767f798f2025f68a4749b841d7ae2e37837d6f58b030

This issue is linked to #600 as the same initial error was faced, but is describing an additional issue after a workaround for #600 has been implemented (see step 5 below)

To Reproduce Steps to reproduce the behavior:

  1. Add "gunicorn" package in the requirements.txt file to avoid #600
  2. Build the Docker image (whether locally or using Azure DevOps - got the same result)
  3. Push the docker image to an Azure Container Registry
  4. Create a web app and point to this image
  5. Navigate to the web app: the web app never launches

Expected behavior The web app should display the webchat

Screenshots The web app never launches. Logs from the web app indicate the following:

2024-02-05T09:15:06.587Z INFO  - Waiting for response to warmup request for container app-XXXXXXX. Elapsed time = 30.8322763 sec
...
2024-02-05T09:18:12.666Z INFO  - Waiting for response to warmup request for container app-XXXXXXX. Elapsed time = 216.9114374 sec
2024-02-05T09:18:25.836Z ERROR - Container app-XXXXXXX for site app-YYYYY did not start within expected time limit. Elapsed time = 230.0819147 sec
2024-02-05T09:18:25.837Z INFO  - Initiating warmup request to container app-XXXXXXX_middleware for site app-YYYYY
2024-02-05T09:18:26.110Z INFO  - Container app-XXXXXXX_middleware for site app-YYYYY initialized successfully and is ready to serve requests.
2024-02-05T09:18:26.122Z ERROR - Container app-XXXXXXX didn't respond to HTTP pings on port: 80, failing site start. See container logs for debugging.
2024-02-05T09:18:26.336Z INFO  - Stopping site app-YYYYY because it failed during startup.

Configuration: Please provide the following Bug related to app startup and happens with any openAI model / chat history setup etc.

Additional context I find a solution but did not had time to create a good PR to push it (I'm leaving for 2 weeks in a few hours) - if it can help and has not been pushed / fixed, I will add it end of February.

The solution is to configure a port number (doc) by adding "WEBSITES_PORT" with value 8000 in the App Service configuration settings as it is the port where Gunicorn listens

QuentinAd commented 9 months ago

@nrobert, I had a slightly different fix but same logic about the binding port.

Added the missing 80 in the bind

"""gunicorn.conf.py"""
import multiprocessing

max_requests = 1000
max_requests_jitter = 50
log_file = "-"
bind = "0.0.0.0:80"

timeout = 230

num_cpus = multiprocessing.cpu_count()
workers = (num_cpus * 2) + 1
worker_class = "uvicorn.workers.UvicornWorker"

Also:

# WebApp.DockerFile starting at line 21
    && pip install --no-cache-dir uvicorn gunicorn # added uvicorn and gunicorn instead of wsgi

COPY requirements.txt /usr/src/app/  
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt \  
    && rm -rf /root/.cache  

COPY . /usr/src/app/  
COPY --from=frontend /home/node/app/static  /usr/src/app/static/
WORKDIR /usr/src/app  

EXPOSE 80  
CMD ["gunicorn", "app:app", "-c", "gunicorn.conf.py"] # edited this too and explicitly mentioned reference to gunicorn.conf.py
nrobert commented 9 months ago

@nrobert, I had a slightly different fix but same logic about the binding port. Added the missing 80 in the bind

That's another way which is fine locally. I'm not 100% sure that it will work on an App Service on Azure (based on a few search, for example this: https://stackoverflow.com/a/12812895/3136339 and this: https://copyprogramming.com/howto/gunicorn-not-starting-on-port-80-but-starting-on-port-8000) but I haven't tested your option to ensure that it is the case

sarah-widder commented 9 months ago

What's working for me is adding gunicorn to requirements.txt, and modifying the dockerfile CMD to CMD ["gunicorn" , "-b", "0.0.0.0:80", "app:app"]

This works locally (docker run -it -d -p 8000:8000 myimagename) and in a deployed app.

We're still fully validating this then will push the PR.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 weeks ago

This issue was closed because it has been inactive for 14 days since being marked as stale.