|
| 1 | +# Autogenerated warning: |
| 2 | +# This file is generated from Dockerfile.jinja2. Do not edit the Dockerfile.cuda|cpu|amd file directly. |
| 3 | +# Only contribute to the Dockerfile.jinja2 and dockerfile_template.yaml and regenerate the Dockerfile.cuda|cpu|amd |
| 4 | + |
| 5 | +FROM ubuntu:22.04 AS base |
| 6 | + |
| 7 | +ENV PYTHONUNBUFFERED=1 \ |
| 8 | + \ |
| 9 | + # pip |
| 10 | + PIP_NO_CACHE_DIR=off \ |
| 11 | + PIP_DISABLE_PIP_VERSION_CHECK=on \ |
| 12 | + PIP_DEFAULT_TIMEOUT=100 \ |
| 13 | + \ |
| 14 | + # make poetry create the virtual environment in the project's root |
| 15 | + # it gets named `.venv` |
| 16 | + POETRY_VIRTUALENVS_CREATE="true" \ |
| 17 | + POETRY_VIRTUALENVS_IN_PROJECT="true" \ |
| 18 | + # do not ask any interactive question |
| 19 | + POETRY_NO_INTERACTION=1 \ |
| 20 | + EXTRAS="all" \ |
| 21 | + PYTHON="python3.11" |
| 22 | +RUN apt-get update && apt-get install --no-install-recommends -y build-essential python3-dev libsndfile1 $PYTHON-venv $PYTHON curl |
| 23 | +WORKDIR /app |
| 24 | + |
| 25 | +FROM base as builder |
| 26 | +# Set the working directory for the app |
| 27 | +# Define the version of Poetry to install (default is 1.7.1) |
| 28 | +# Define the directory to install Poetry to (default is /opt/poetry) |
| 29 | +ARG POETRY_VERSION=1.8.4 |
| 30 | +ARG POETRY_HOME=/opt/poetry |
| 31 | +# Create a Python virtual environment for Poetry and install it |
| 32 | +RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=$POETRY_HOME POETRY_VERSION=$POETRY_VERSION $PYTHON - |
| 33 | +ENV PATH=$POETRY_HOME/bin:$PATH |
| 34 | +# Test if Poetry is installed in the expected path |
| 35 | +RUN echo "Poetry version:" && poetry --version |
| 36 | +# Copy the rest of the app source code (this layer will be invalidated and rebuilt whenever the source code changes) |
| 37 | +COPY poetry.lock poetry.toml pyproject.toml README.md /app/ |
| 38 | +# Install dependencies only |
| 39 | +# |
| 40 | +# "RUN poetry install --no-interaction --no-ansi --no-root --extras \"${EXTRAS}\" --without lint,test && poetry cache clear pypi --all" |
| 41 | +COPY requirements_install_from_poetry.sh requirements_install_from_poetry.sh |
| 42 | +RUN ./requirements_install_from_poetry.sh --no-root --without lint,test "https://download.pytorch.org/whl/cpu" |
| 43 | + |
| 44 | +RUN poetry run python -m pip install --upgrade --upgrade-strategy eager "optimum[openvino]" |
| 45 | + |
| 46 | +COPY infinity_emb infinity_emb |
| 47 | +# Install dependency with infinity_emb package |
| 48 | +# "RUN poetry install --no-interaction --no-ansi --extras \"${EXTRAS}\" --without lint,test && poetry cache clear pypi --all" |
| 49 | +COPY requirements_install_from_poetry.sh requirements_install_from_poetry.sh |
| 50 | +RUN ./requirements_install_from_poetry.sh --without lint,test "https://download.pytorch.org/whl/cpu" |
| 51 | + |
| 52 | +# |
| 53 | + |
| 54 | + |
| 55 | +FROM builder as testing |
| 56 | +# install lint and test dependencies |
| 57 | +# "RUN poetry install --no-interaction --no-ansi --extras \"${EXTRAS}\" --with lint,test && poetry cache clear pypi --all" |
| 58 | +COPY requirements_install_from_poetry.sh requirements_install_from_poetry.sh |
| 59 | +RUN ./requirements_install_from_poetry.sh --with lint,test "https://download.pytorch.org/whl/cpu" |
| 60 | + |
| 61 | +# # lint |
| 62 | +# # RUN poetry run ruff check . |
| 63 | +# # RUN poetry run mypy . |
| 64 | +# # pytest |
| 65 | +# COPY tests tests |
| 66 | +# # run end to end tests because of duration of build in github ci. |
| 67 | +# # Run tests/end_to_end on TARGETPLATFORM x86_64 otherwise run tests/end_to_end_gpu |
| 68 | +# # poetry run python -m pytest tests/end_to_end -x # TODO: does not work. |
| 69 | +# RUN if [ -z "$TARGETPLATFORM" ]; then \ |
| 70 | +# ARCH=$(uname -m); \ |
| 71 | +# if [ "$ARCH" = "x86_64" ]; then \ |
| 72 | +# TARGETPLATFORM="linux/amd64"; \ |
| 73 | +# elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then \ |
| 74 | +# TARGETPLATFORM="linux/arm64"; \ |
| 75 | +# else \ |
| 76 | +# echo "Unsupported architecture: $ARCH"; exit 1; \ |
| 77 | +# fi; \ |
| 78 | +# fi; \ |
| 79 | +# echo "Running tests on TARGETPLATFORM=$TARGETPLATFORM"; \ |
| 80 | +# if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then \ |
| 81 | +# poetry run python -m pytest tests/end_to_end/test_api_with_dummymodel.py -x ; \ |
| 82 | +# else \ |
| 83 | +# poetry run python -m pytest tests/end_to_end/test_api_with_dummymodel.py tests/end_to_end/test_sentence_transformers.py -m "not performance" -x ; \ |
| 84 | +# fi |
| 85 | +# RUN echo "all tests passed" > "test_results.txt" |
| 86 | + |
| 87 | + |
| 88 | +# # Use a multi-stage build -> production version, with download |
| 89 | +# FROM base AS tested-builder |
| 90 | +# COPY --from=builder /app /app |
| 91 | +# # force testing stage to run |
| 92 | +# COPY --from=testing /app/test_results.txt /app/test_results.txt |
| 93 | +# ENV HF_HOME=/app/.cache/huggingface |
| 94 | +# ENV PATH=/app/.venv/bin:$PATH |
| 95 | +# # do nothing |
| 96 | +# RUN echo "copied all files" |
| 97 | + |
| 98 | + |
| 99 | +# Export with tensorrt, not recommended. |
| 100 | +# docker buildx build --target=production-tensorrt -f Dockerfile . |
| 101 | +# FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 AS production-tensorrt |
| 102 | +# ENV PYTHONUNBUFFERED=1 \ |
| 103 | +# PIP_NO_CACHE_DIR=off \ |
| 104 | +# PYTHON="python3.11" |
| 105 | +# RUN apt-get update && apt-get install python3-dev python3-pip $PYTHON build-essential curl -y |
| 106 | +# COPY --from=builder /app /app |
| 107 | +# # force testing stage to run |
| 108 | +# COPY --from=testing /app/test_results.txt /app/test_results.txt |
| 109 | +# ENV HF_HOME=/app/.cache/torch |
| 110 | +# ENV PATH=/app/.venv/bin:$PATH |
| 111 | +# RUN pip install --no-cache-dir "onnxruntime-gpu==1.17.0" "tensorrt==8.6.*" |
| 112 | +# ENV LD_LIBRARY_PATH /app/.venv/lib/$(PYTHON)/site-packages/tensorrt:/usr/lib/x86_64-linux-gnu:/app/.venv/lib/$(PYTHON)/site-packages/tensorrt_libs:${LD_LIBRARY_PATH} |
| 113 | +# ENV PATH /app/.venv/lib/$(PYTHON)/site-packages/tensorrt/bin:${PATH} |
| 114 | +# ENTRYPOINT ["infinity_emb"] |
| 115 | + |
| 116 | + |
| 117 | +# # Use a multi-stage build -> production version, with download |
| 118 | +# # docker buildx build --target=production-with-download \ |
| 119 | +# # --build-arg MODEL_NAME=BAAI/bge-small-en-v1.5 --build-arg ENGINE=torch -f Dockerfile -t infinity-BAAI-small . |
| 120 | +# FROM tested-builder AS production-with-download |
| 121 | +# # collect model name and engine from build args |
| 122 | +# ARG MODEL_NAME |
| 123 | +# RUN if [ -z "${MODEL_NAME}" ]; then echo "Error: Build argument MODEL_NAME not set." && exit 1; fi |
| 124 | +# ARG ENGINE |
| 125 | +# RUN if [ -z "${ENGINE}" ]; then echo "Error: Build argument ENGINE not set." && exit 1; fi |
| 126 | +# # will exit with 3 if model is downloaded # TODO: better exit code |
| 127 | +# RUN infinity_emb v2 --model-id $MODEL_NAME --engine $ENGINE --preload-only || [ $? -eq 3 ] |
| 128 | +# ENTRYPOINT ["infinity_emb"] |
| 129 | + |
| 130 | +# # Use a multi-stage build -> production version |
| 131 | +# FROM tested-builder AS production |
| 132 | +# ENTRYPOINT ["infinity_emb"] |
0 commit comments