|
| 1 | +# syntax = docker/dockerfile:experimental |
| 2 | +# |
| 3 | +# This file can build images for CPU & GPU with CPP backend support. |
| 4 | +# |
| 5 | +# Following comments have been shamelessly copied from https://github.com/pytorch/pytorch/blob/master/Dockerfile |
| 6 | +# |
| 7 | +# NOTE: To build this you will need a docker version > 18.06 with |
| 8 | +# experimental enabled and DOCKER_BUILDKIT=1 |
| 9 | +# |
| 10 | +# If you do not use buildkit you are not going to have a good time |
| 11 | +# |
| 12 | +# For reference: |
| 13 | +# https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 14 | + |
| 15 | + |
| 16 | +ARG BASE_IMAGE=ubuntu:20.04 |
| 17 | +ARG PYTHON_VERSION=3.9 |
| 18 | +ARG CMAKE_VERSION=3.26.4 |
| 19 | +ARG BRANCH_NAME="master" |
| 20 | +ARG USE_CUDA_VERSION="" |
| 21 | + |
| 22 | +FROM ${BASE_IMAGE} AS cpp-dev-image |
| 23 | +ARG BASE_IMAGE |
| 24 | +ARG PYTHON_VERSION |
| 25 | +ARG CMAKE_VERSION |
| 26 | +ARG BRANCH_NAME |
| 27 | +ARG USE_CUDA_VERSION |
| 28 | +ENV PYTHONUNBUFFERED TRUE |
| 29 | + |
| 30 | +RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ |
| 31 | + apt-get update && \ |
| 32 | + apt-get install software-properties-common -y && \ |
| 33 | + add-apt-repository -y ppa:deadsnakes/ppa && \ |
| 34 | + DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ |
| 35 | + sudo \ |
| 36 | + vim \ |
| 37 | + git \ |
| 38 | + curl \ |
| 39 | + wget \ |
| 40 | + rsync \ |
| 41 | + gpg \ |
| 42 | + ca-certificates \ |
| 43 | + lsb-release \ |
| 44 | + openjdk-17-jdk \ |
| 45 | + python$PYTHON_VERSION \ |
| 46 | + python$PYTHON_VERSION-dev \ |
| 47 | + python$PYTHON_VERSION-venv \ |
| 48 | + && rm -rf /var/lib/apt/lists/* |
| 49 | +
|
| 50 | +# Create a virtual environment and "activate" it by adding it first to the path. |
| 51 | +RUN python$PYTHON_VERSION -m venv /home/venv |
| 52 | +ENV PATH="/home/venv/bin:$PATH" |
| 53 | +
|
| 54 | +# Enable installation of recent cmake release |
| 55 | +# Ref: https://apt.kitware.com/ |
| 56 | +RUN (wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null) \ |
| 57 | + && (echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null) \ |
| 58 | + && apt-get update \ |
| 59 | + && (test -f /usr/share/doc/kitware-archive-keyring/copyright || sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg) \ |
| 60 | + && sudo apt-get install kitware-archive-keyring \ |
| 61 | + && rm -rf /var/lib/apt/lists/* |
| 62 | +
|
| 63 | +# Pin cmake and cmake-data version |
| 64 | +# Ref: https://manpages.ubuntu.com/manpages/xenial/man5/apt_preferences.5.html |
| 65 | +RUN echo "Package: cmake\nPin: version $CMAKE_VERSION*\nPin-Priority: 1001" > /etc/apt/preferences.d/cmake |
| 66 | +RUN echo "Package: cmake-data\nPin: version $CMAKE_VERSION*\nPin-Priority: 1001" > /etc/apt/preferences.d/cmake-data |
| 67 | +
|
| 68 | +# Install CUDA toolkit to enable "libtorch" build with GPU support |
| 69 | +RUN apt-get update && \ |
| 70 | + if echo "$BASE_IMAGE" | grep -q "cuda:"; then \ |
| 71 | + if [ "$USE_CUDA_VERSION" = "cu121" ]; then \ |
| 72 | + apt-get -y install cuda-toolkit-12-1; \ |
| 73 | + elif [ "$USE_CUDA_VERSION" = "cu118" ]; then \ |
| 74 | + apt-get -y install cuda-toolkit-11-8; \ |
| 75 | + else \ |
| 76 | + echo "Cuda version not supported by CPP backend: $USE_CUDA_VERSION"; \ |
| 77 | + exit 1; \ |
| 78 | + fi; \ |
| 79 | + fi \ |
| 80 | + && rm -rf /var/lib/apt/lists/* |
| 81 | +
|
| 82 | +RUN git clone --recursive https://github.com/pytorch/serve.git \ |
| 83 | + && cd serve \ |
| 84 | + && git checkout ${BRANCH_NAME} |
| 85 | +
|
| 86 | +WORKDIR "serve" |
| 87 | +
|
| 88 | +# CPP backend binary install depends on "ts" directory being present in python site-packages |
| 89 | +RUN pip install pygit2 && python ts_scripts/install_from_src.py |
| 90 | +
|
| 91 | +EXPOSE 8080 8081 8082 7070 7071 |
0 commit comments