If I clone Miguel Grinberg's flask-sock and run examples/clock.py
I get a templates/clock.html
which receives time updates every second over a web socket.
If I then put a dockerfile
into the project and install the dependencies I can get a deployment onto Cloud Run but clock.html
doesn't receive the messages. I can see the websocket is up using Chrome's dev tools. If I hit the stop button on the page then it logs [Stopped] which implies it received the close
event over the websocket.
I'm using VSCode with the Cloud Code extension to deploy to Cloud Run. I get the same behaviour on the the emulator. I've removed EXEC
from the gunicorn line and taken the Python version down to 3.9.6 from 3.10-alpine in desperation. I've modified clock.html
to use wss
rather than ws
.
dockerfile:
# Python image to use.
FROM python:3.9.6
# Set the working directory to /app
WORKDIR /app
# copy the requirements file used for dependencies
COPY requirements.txt .
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Copy the rest of the working directory contents into the container at /app
COPY . .
# Run app.py when the container launches
# ENTRYPOINT ["python", "app.py"]
ENV PYTHONUNBUFFERED=1
ENV GEVENT_SUPPORT=True
CMD gunicorn -k gevent -b 0.0.0.0:$PORT --workers 1 --threads 8 --timeout 0 --chdir examples clock:app
#CMD gunicorn -b 0.0.0.0:$PORT --workers 1 --threads 8 app:app