private-gpt/Dockerfile.external
2024-05-04 19:27:24 +05:45

71 lines
2.2 KiB
Text

FROM python:3.11.6-slim-bookworm as base
# Set noninteractive mode
ENV DEBIAN_FRONTEND noninteractive
# Install necessary dependencies including CMake and g++
RUN apt-get update && apt-get install -y \
libopenblas-dev \
ninja-build \
build-essential \
pkg-config \
wget \
libgl1-mesa-glx \
python3-opencv
# Install poetry
RUN pip install pipx
RUN python3 -m pipx ensurepath
RUN pipx install poetry
ENV PATH="/root/.local/bin:$PATH"
ENV PATH=".venv/bin/:$PATH"
# https://python-poetry.org/docs/configuration/#virtualenvsin-project
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
FROM base as dependencies
WORKDIR /home/worker/app
COPY pyproject.toml poetry.lock ./
RUN poetry install --extras "ui vector-stores-qdrant llms-ollama embeddings-ollama"
FROM base as app
ENV PYTHONUNBUFFERED=1
ENV PORT=8000
# Prepare a non-root user
RUN adduser --system worker
WORKDIR /home/worker/app
RUN mkdir local_data; chown worker local_data
RUN mkdir models; chown worker models
RUN mkdir tiktoken_cache; chown worker tiktoken_cache
RUN mkdir static; chown worker static
RUN mkdir static/unchecked; chown worker static/unchecked
RUN mkdir static/checked; chown worker static/checked
RUN mkdir uploads; chown worker uploads
COPY --chown=worker --from=dependencies /home/worker/app/.venv/ .venv
COPY --chown=worker private_gpt/ private_gpt
COPY --chown=worker alembic/ alembic
COPY --chown=worker fern/ fern
COPY --chown=worker *.yaml *.md ./
COPY --chown=worker scripts/ scripts
COPY --chown=worker *.ini ./
# Copy the docker-entrypoint.sh file and make it executable
COPY --chown=worker docker-entrypoint.sh /home/worker/app/
RUN chmod +x /home/worker/app/docker-entrypoint.sh
########################################
#### ---- Set up NVIDIA-Docker ---- ####
########################################
## ref: https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support)#usage
ENV TOKENIZERS_PARALLELISM=false
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
# Set the user to run the container
USER worker
EXPOSE 8000
# Copy the rest of the application code into the container
COPY --chown=worker . /home/worker/app
# Set the entrypoint
ENTRYPOINT ["/home/worker/app/docker-entrypoint.sh"]