diff --git a/docker/Dockerfile b/docker/Dockerfile index a6d6382d7a..333f585047 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -47,6 +47,7 @@ RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ python$PYTHON_VERSION-venv \ openjdk-17-jdk \ curl \ + git \ && rm -rf /var/lib/apt/lists/* # Make the virtual environment and "activating" it by adding it first to the path. @@ -62,26 +63,29 @@ RUN export USE_CUDA=1 ARG CUDA_VERSION="" -RUN TORCH_VER=$(curl --silent --location https://pypi.org/pypi/torch/json | python -c "import sys, json, pkg_resources; releases = json.load(sys.stdin)['releases']; print(sorted(releases, key=pkg_resources.parse_version)[-1])") && \ - TORCH_VISION_VER=$(curl --silent --location https://pypi.org/pypi/torchvision/json | python -c "import sys, json, pkg_resources; releases = json.load(sys.stdin)['releases']; print(sorted(releases, key=pkg_resources.parse_version)[-1])") && \ +RUN git clone --depth 1 https://github.com/pytorch/serve.git + +WORKDIR "serve" + +RUN \ if echo "$BASE_IMAGE" | grep -q "cuda:"; then \ # Install CUDA version specific binary when CUDA version is specified as a build arg if [ "$CUDA_VERSION" ]; then \ - python -m pip install --no-cache-dir torch==$TORCH_VER+$CUDA_VERSION torchvision==$TORCH_VISION_VER+$CUDA_VERSION -f https://download.pytorch.org/whl/torch_stable.html; \ - # Install the binary with the latest CUDA version support + python ./ts_scripts/install_dependencies.py --cuda $CUDA_VERSION; \ + # Install the binary with the latest CPU image on a CUDA base image else \ - python -m pip install --no-cache-dir torch torchvision; \ + python ./ts_scripts/install_dependencies.py; \ fi; \ - python -m pip install --no-cache-dir -r https://raw.githubusercontent.com/pytorch/serve/master/requirements/common.txt; \ # Install the CPU binary else \ - python -m pip install --no-cache-dir torch==$TORCH_VER+cpu torchvision==$TORCH_VISION_VER+cpu -f https://download.pytorch.org/whl/torch_stable.html; \ + python ./ts_scripts/install_dependencies.py; \ fi -RUN python -m pip install --no-cache-dir captum torchtext torchserve torch-model-archiver pyyaml +# Make sure latest version of torchserve is uploaded before running this +RUN python -m pip install --no-cache-dir torchserve torch-model-archiver torch-workflow-archiver # Final image for production -FROM ${BASE_IMAGE} AS runtime-image +FROM ${BASE_IMAGE} AS runtime-image # Re-state ARG PYTHON_VERSION to make it active in this build-stage (uses default define at the top) ARG PYTHON_VERSION ENV PYTHONUNBUFFERED TRUE