|
1 | | -FROM python:3.11 |
| 1 | +FROM python:3.13 AS python-base |
2 | 2 |
|
3 | | -# Update packagtes, install necessary tools into the base image, clean up and clone git repository |
4 | | -RUN apt update \ |
5 | | - && apt install -y --no-install-recommends --no-install-suggests git apache2 \ |
6 | | - && apt autoremove -y --purge \ |
7 | | - && apt clean \ |
8 | | - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ |
9 | | - && git clone https://github.com/ParisNeo/ollama_proxy_server.git |
| 3 | +# https://python-poetry.org/docs#ci-recommendations |
| 4 | +ENV POETRY_VERSION=2.1.3 |
| 5 | +ENV POETRY_HOME=/opt/poetry |
| 6 | +ENV POETRY_VENV=/opt/poetry-venv |
10 | 7 |
|
11 | | -# Change working directory to cloned git repository |
12 | | -WORKDIR ollama_proxy_server |
| 8 | +# Tell Poetry where to place its cache and virtual environment |
| 9 | +ENV POETRY_CACHE_DIR=/opt/.cache |
13 | 10 |
|
14 | | -# Install all needed requirements |
15 | | -RUN pip3 install -e . |
| 11 | +# Create stage for Poetry installation |
| 12 | +FROM python-base AS poetry-base |
16 | 13 |
|
17 | | -# Copy config.ini and authorized_users.txt into project working directory |
18 | | -COPY config.ini . |
19 | | -COPY authorized_users.txt . |
| 14 | +# Creating a virtual environment just for poetry and install it with pip |
| 15 | +RUN python3 -m venv $POETRY_VENV \ |
| 16 | + && $POETRY_VENV/bin/pip install -U pip setuptools \ |
| 17 | + && $POETRY_VENV/bin/pip install poetry==${POETRY_VERSION} |
| 18 | + |
| 19 | +# Copy Poetry to app image |
| 20 | +# COPY --from=poetry-base ${POETRY_VENV} ${POETRY_VENV} |
| 21 | + |
| 22 | +# Add Poetry to PATH |
| 23 | +ENV PATH="${PATH}:${POETRY_VENV}/bin" |
| 24 | + |
| 25 | +# temp dir |
| 26 | +WORKDIR /app-tmp |
| 27 | + |
| 28 | +# Copy Dependencies |
| 29 | +COPY --chown=worker:worker poetry.lock pyproject.toml ./ |
| 30 | + |
| 31 | +# [OPTIONAL] Validate the project is properly configured |
| 32 | +RUN poetry check |
| 33 | + |
| 34 | +# Copy Application |
| 35 | +COPY --chown=worker:worker . ./ |
| 36 | + |
| 37 | +# build and install the app |
| 38 | +RUN poetry build |
20 | 39 |
|
21 | | -# Start the proxy server as entrypoint |
22 | | -ENTRYPOINT ["ollama_proxy_server"] |
| 40 | +# Create a new stage from the base python image |
| 41 | +FROM python-base AS ollama-proxy-server |
| 42 | + |
| 43 | +RUN adduser worker |
| 44 | +WORKDIR /home/worker |
| 45 | + |
| 46 | +# copy wheel and tgz |
| 47 | +COPY --from=poetry-base /app-tmp/dist ./dist |
| 48 | + |
| 49 | +RUN pip install dist/*.whl |
| 50 | + |
| 51 | +RUN rm -fr ./dist |
| 52 | + |
| 53 | +# copy entry point |
| 54 | +COPY --from=poetry-base /app-tmp/entry-point.sh / |
| 55 | + |
| 56 | +USER worker |
| 57 | + |
| 58 | +# Copy config.ini and authorized_users.txt into project working directory |
| 59 | +COPY --chown=worker:worker config.ini . |
| 60 | +COPY --chown=worker:worker authorized_users.txt . |
23 | 61 |
|
24 | 62 | # Do not buffer output, e.g. logs to stdout |
25 | 63 | ENV PYTHONUNBUFFERED=1 |
26 | 64 |
|
27 | | -# Set command line parameters |
28 | | -CMD ["--config", "./config.ini", "--users_list", "./authorized_users.txt", "--port", "8080"] |
| 65 | +# Run Application |
| 66 | +EXPOSE 8080 |
| 67 | +ENTRYPOINT ["/entry-point.sh"] |
0 commit comments