-
Notifications
You must be signed in to change notification settings - Fork 119
/
Dockerfile
133 lines (105 loc) · 3.65 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# syntax=docker/dockerfile:1
# Keep this syntax directive! It's used to enable Docker BuildKit
ARG PYTHON_VERSION=3.11.7
ARG PORT=8000
ARG POETRY_INSTALL_ARGS=""
################################
# PYTHON-BASE
# Sets up all our shared environment variables
################################
FROM python:${PYTHON_VERSION}-slim as python-base
# Python
ENV PYTHONUNBUFFERED=1 \
# pip
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# Poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.7.1 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
# never create virtual environment automaticly, only use env prepared by us
POETRY_VIRTUALENVS_CREATE=false \
# this is where our requirements + virtual environment will live
VIRTUAL_ENV="/venv"
# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VIRTUAL_ENV/bin:$PATH"
# prepare virtual env
RUN python -m venv $VIRTUAL_ENV
# working directory and Python path
WORKDIR /app
ENV PYTHONPATH="/app:$PYTHONPATH"
################################
# BUILDER-BASE
# Used to build deps + create our virtual environment
################################
FROM python-base as builder-base
RUN apt-get update && \
apt-get install -y \
apt-transport-https \
gnupg \
ca-certificates \
build-essential \
git \
vim \
curl
# install poetry - respects $POETRY_VERSION & $POETRY_HOME
# The --mount will mount the buildx cache directory to where
# Poetry and Pip store their cache so that they can re-use it
RUN --mount=type=cache,target=/root/.cache \
curl -sSL https://install.python-poetry.org | python -
# used to init dependencies
WORKDIR /app
COPY pyproject.toml ./
RUN poetry lock
ARG POETRY_INSTALL_ARGS
# install runtime deps to VIRTUAL_ENV
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-root --only main $POETRY_INSTALL_ARGS
################################
# DEVELOPMENT
# Image used during development / testing
################################
FROM builder-base as development
WORKDIR /app
COPY --from=builder-base /app/pyproject.toml pyproject.toml
COPY --from=builder-base /app/poetry.lock poetry.lock
ARG POETRY_INSTALL_ARGS
# quicker install as runtime deps are already installed
RUN --mount=type=cache,target=/root/.cache \
poetry install --no-root --with dev $POETRY_INSTALL_ARGS
COPY . .
RUN poetry install --only-root $POETRY_INSTALL_ARGS
ARG PORT
EXPOSE $PORT
CMD ["bash"]
################################
# PRODUCTION
# Final image used for runtime
################################
FROM python-base as production
ENV WORKER_COUNT=1
LABEL org.opencontainers.image.source="https://github.com/pinecone-io/canopy"
LABEL org.opencontainers.image.description="Retrieval Augmented Generation (RAG) framework and context engine powered by Pinecone"
LABEL org.opencontainers.image.licenses="Apache-2.0"
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates && \
apt-get clean
# copy in our built poetry + venv
COPY --from=builder-base $POETRY_HOME $POETRY_HOME
COPY --from=builder-base $VIRTUAL_ENV $VIRTUAL_ENV
WORKDIR /app
COPY --from=builder-base /app/pyproject.toml pyproject.toml
COPY --from=builder-base /app/poetry.lock poetry.lock
COPY src/ src/
RUN touch README.md
ARG POETRY_INSTALL_ARGS
RUN poetry install --only-root $POETRY_INSTALL_ARGS
ARG PORT
EXPOSE $PORT
ENV PORT $PORT
CMD ["sh", "-c", "gunicorn canopy_server.app:app --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT --workers $WORKER_COUNT"]