Created
October 3, 2022 10:06
-
-
Save spookyuser/dddd2764a6257a07ba22d428f002ee87 to your computer and use it in GitHub Desktop.
Baking sentence transformers into docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.10.7-slim as base | |
ENV PYTHONFAULTHANDLER=1 \ | |
PYTHONUNBUFFERED=1 \ | |
PYTHONHASHSEED=random \ | |
PIP_NO_CACHE_DIR=off \ | |
PIP_DISABLE_PIP_VERSION_CHECK=on \ | |
PIP_DEFAULT_TIMEOUT=100 \ | |
PIPENV_NOSPIN=true \ | |
NUMBA_CACHE_DIR=/tmp \ | |
PYTHONPATH=/app \ | |
LC_ALL=C.UTF-8 \ | |
LANG=C.UTF-8 \ | |
DEBIAN_FRONTEND=noninteractive | |
FROM base AS python-deps | |
RUN pip install pipenv==2022.8.24 | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
gcc \ | |
libc-dev \ | |
&& rm -rf /var/lib/apt/lists/* | |
COPY Pipfile . | |
COPY Pipfile.lock . | |
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install | |
FROM base AS runtime | |
# Copy virtual env from python-deps stage | |
COPY --from=python-deps /.venv /.venv | |
ENV PATH="/.venv/bin:$PATH" | |
# Create and switch to a new user | |
RUN useradd --create-home appuser | |
USER appuser | |
RUN python -c 'from sentence_transformers import SentenceTransformer; embedder = SentenceTransformer("all-mpnet-base-v2")' | |
COPY . /app | |
# RUN python test.py | |
CMD exec gunicorn --bind :$PORT --log-level info --workers 3 --threads 8 --timeout 0 app:server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment