From b4c35ea57898327b0d36e73dcf13e26f52390113 Mon Sep 17 00:00:00 2001 From: Olly Welch Date: Tue, 28 Feb 2023 22:06:39 +0000 Subject: [PATCH] Use gunicorn as WSGI server in ML image --- machine-learning/Dockerfile | 4 ++-- machine-learning/gunicorn.conf.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 machine-learning/gunicorn.conf.py diff --git a/machine-learning/Dockerfile b/machine-learning/Dockerfile index 5c905295c8..852624160f 100644 --- a/machine-learning/Dockerfile +++ b/machine-learning/Dockerfile @@ -6,7 +6,7 @@ ENV PYTHONDONTWRITEBYTECODE=1 \ RUN python -m venv /opt/venv && \ /opt/venv/bin/pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html && \ - /opt/venv/bin/pip install transformers tqdm numpy scikit-learn scipy nltk sentencepiece flask Pillow && \ + /opt/venv/bin/pip install transformers tqdm numpy scikit-learn scipy nltk sentencepiece flask Pillow gunicorn && \ /opt/venv/bin/pip install --no-deps sentence-transformers FROM python:3.10-slim @@ -22,4 +22,4 @@ WORKDIR /usr/src/app COPY . . -CMD ["python", "src/main.py"] +CMD ["gunicorn", "src.main:server"] diff --git a/machine-learning/gunicorn.conf.py b/machine-learning/gunicorn.conf.py new file mode 100644 index 0000000000..51704b6155 --- /dev/null +++ b/machine-learning/gunicorn.conf.py @@ -0,0 +1,13 @@ +""" +Gunicorn configuration options. +https://docs.gunicorn.org/en/stable/settings.html#config-file +""" +import os + + +# Set the bind address based on the env +server_port = os.getenv('MACHINE_LEARNING_PORT') or "3003" +bind = f"127.0.0.1:{server_port}" + +# Preload the Flask app / models etc. before starting the server +preload_app = True