Skip to content

Commit

Permalink
Another try
Browse files Browse the repository at this point in the history
  • Loading branch information
bdb-dd committed Jan 22, 2024
1 parent e052ea5 commit 7d01e0a
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# but I try to keep it updated (see history)

################################
# PYTHON-BASE
# poetry-base
# Sets up all our shared environment variables
################################
FROM python:3.11-slim as python-base
FROM python:3.11-slim as poetry-base

# python
ENV PYTHONUNBUFFERED=1 \
Expand All @@ -34,19 +34,12 @@ ENV PYTHONUNBUFFERED=1 \
# paths
# this is where our requirements + virtual environment will live
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv" \
APP_PATH="/opt/pysetup/.venv/app/"
VENV_PATH="/opt/pysetup/.venv"


# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"


################################
# BUILDER-BASE
# Used to build deps + create our virtual environment
################################
FROM python-base as builder-base
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
Expand All @@ -62,40 +55,37 @@ RUN apt-get update \
RUN --mount=type=cache,target=/root/.cache \
curl -sSL https://install.python-poetry.org | python3 -

# copy project requirement files here to ensure they will be cached.
# copy app files here to ensure they will be cached.
WORKDIR $PYSETUP_PATH
COPY poetry.lock pyproject.toml ./
COPY . ./

# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-root

# --> also download required ColBERT model files
COPY ./docs_qa/preload_colbert.py ./app/docs_qa/preload_colbert.py
RUN poetry run python ./app/docs_qa/preload_colbert.py

# copy in our app files
COPY ./ /app/
################################
# BUILDER-BASE
# Used to build deps + create our virtual environment
################################
FROM poetry-base as builder-base

WORKDIR $PYSETUP_PATH

# --> also download required ColBERT model files
RUN poetry run python docs_qa/preload_colbert.py


################################
# PRODUCTION
# Final image used for runtime
################################
FROM python-base as production
FROM poetry-base as production
ENV FASTAPI_ENV=production
WORKDIR $PYSETUP_PATH

# copy in our built poetry + venv
# copy in our built poetry, venv and app
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH

# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-root

# copy in our app files
COPY --from=builder-base /app/ /app/
WORKDIR /app/

CMD ["poetry", "run", "python", "bolt.py"]

0 comments on commit 7d01e0a

Please sign in to comment.