Skip to content

Commit

Permalink
Install from source for a specific branch with docker (#3055)
Browse files Browse the repository at this point in the history
* install from source for a specific branch

* Build docker images with local changes and TS from source

* Use local changes by default. Switched the local option to remote
  • Loading branch information
agunapal authored Apr 6, 2024
1 parent 4f90708 commit 8450a2e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
41 changes: 31 additions & 10 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ FROM ${BASE_IMAGE} AS compile-image
ARG BASE_IMAGE=ubuntu:rolling
ARG PYTHON_VERSION
ARG BUILD_NIGHTLY
ARG BUILD_FROM_SRC
ARG LOCAL_CHANGES
ARG BRANCH_NAME
ENV PYTHONUNBUFFERED TRUE

RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \
Expand Down Expand Up @@ -64,18 +67,25 @@ RUN export USE_CUDA=1

ARG USE_CUDA_VERSION=""

RUN git clone --depth 1 --recursive https://github.com/pytorch/serve.git
COPY ./ serve

RUN \
if echo "$LOCAL_CHANGES" | grep -q "false"; then \
rm -rf serve;\
git clone --recursive https://github.com/pytorch/serve.git -b $BRANCH_NAME; \
fi


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 [ "$USE_CUDA_VERSION" ]; then \
python ./ts_scripts/install_dependencies.py --cuda $USE_CUDA_VERSION; \
python ./ts_scripts/install_dependencies.py --cuda $USE_CUDA_VERSION;\
# Install the binary with the latest CPU image on a CUDA base image
else \
python ./ts_scripts/install_dependencies.py; \
python ./ts_scripts/install_dependencies.py;\
fi; \
# Install the CPU binary
else \
Expand All @@ -84,7 +94,10 @@ RUN \

# Make sure latest version of torchserve is uploaded before running this
RUN \
if echo "$BUILD_NIGHTLY" | grep -q "false"; then \
if echo "$BUILD_FROM_SRC" | grep -q "true"; then \
python -m pip install -r requirements/developer.txt;\
python ts_scripts/install_from_src.py;\
elif echo "$BUILD_NIGHTLY" | grep -q "false"; then \
python -m pip install --no-cache-dir torchserve torch-model-archiver torch-workflow-archiver;\
else \
python -m pip install --no-cache-dir torchserve-nightly torch-model-archiver-nightly torch-workflow-archiver-nightly;\
Expand Down Expand Up @@ -121,12 +134,12 @@ COPY --chown=model-server --from=compile-image /home/venv /home/venv

ENV PATH="/home/venv/bin:$PATH"

COPY dockerd-entrypoint.sh /usr/local/bin/dockerd-entrypoint.sh
COPY docker/dockerd-entrypoint.sh /usr/local/bin/dockerd-entrypoint.sh

RUN chmod +x /usr/local/bin/dockerd-entrypoint.sh \
&& chown -R model-server /home/model-server

COPY config.properties /home/model-server/config.properties
COPY docker/config.properties /home/model-server/config.properties
RUN mkdir /home/model-server/model-store && chown -R model-server /home/model-server/model-store

EXPOSE 8080 8081 8082 7070 7071
Expand Down Expand Up @@ -187,6 +200,8 @@ FROM ${BASE_IMAGE} as dev-image
# Re-state ARG PYTHON_VERSION to make it active in this build-stage (uses default define at the top)
ARG PYTHON_VERSION
ARG BRANCH_NAME
ARG BUILD_FROM_SRC
ARG LOCAL_CHANGES
ARG BUILD_WITH_IPEX
ARG IPEX_VERSION=1.11.0
ARG IPEX_URL=https://software.intel.com/ipex-whl-stable
Expand Down Expand Up @@ -216,9 +231,15 @@ RUN --mount=type=cache,target=/var/cache/apt \
numactl \
&& if [ "$BUILD_WITH_IPEX" = "true" ]; then apt-get update && apt-get install -y libjemalloc-dev libgoogle-perftools-dev libomp-dev && ln -s /usr/lib/x86_64-linux-gnu/libjemalloc.so /usr/lib/libjemalloc.so && ln -s /usr/lib/x86_64-linux-gnu/libtcmalloc.so /usr/lib/libtcmalloc.so && ln -s /usr/lib/x86_64-linux-gnu/libiomp5.so /usr/lib/libiomp5.so; fi \
&& rm -rf /var/lib/apt/lists/*
RUN git clone --recursive https://github.com/pytorch/serve.git \
&& cd serve \
&& git checkout ${BRANCH_NAME}

COPY ./ serve

RUN \
if echo "$LOCAL_CHANGES" | grep -q "false"; then \
rm -rf serve;\
git clone --recursive https://github.com/pytorch/serve.git -b $BRANCH_NAME; \
fi

COPY --from=compile-image /home/venv /home/venv
ENV PATH="/home/venv/bin:$PATH"
WORKDIR "serve"
Expand All @@ -238,4 +259,4 @@ USER model-server
WORKDIR /home/model-server
ENV TEMP=/home/model-server/tmp
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh"]
CMD ["serve"]
CMD ["serve"]
2 changes: 2 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Use `build_image.sh` script to build the docker images. The script builds the `p
|-ipex, --build-with-ipex| Specify to build with intel_extension_for_pytorch. If not specified, script builds without intel_extension_for_pytorch.|
|-cpp, --build-cpp specify to build TorchServe CPP|
|-n, --nightly| Specify to build with TorchServe nightly.|
|-s, --source| Specify to build with TorchServe from source|
|-r, --remote| Specify to use github remote repo|
|-py, --pythonversion| Specify the python version to use. Supported values `3.8`, `3.9`, `3.10`, `3.11`. Default `3.9`|


Expand Down
18 changes: 15 additions & 3 deletions docker/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ USE_LOCAL_SERVE_FOLDER=false
BUILD_WITH_IPEX=false
BUILD_CPP=false
BUILD_NIGHTLY=false
BUILD_FROM_SRC=false
LOCAL_CHANGES=true
PYTHON_VERSION=3.9

for arg in "$@"
Expand All @@ -33,6 +35,8 @@ do
echo "-cpp, --build-cpp specify to build TorchServe CPP"
echo "-py, --pythonversion specify to python version to use: Possible values: 3.8 3.9 3.10"
echo "-n, --nightly specify to build with TorchServe nightly"
echo "-s, --source specify to build with TorchServe from source"
echo "-l, --local specify to use local TorchServe"
exit 0
;;
-b|--branch_name)
Expand Down Expand Up @@ -97,6 +101,14 @@ do
shift
shift
;;
-s|--source)
BUILD_FROM_SRC=true
shift
;;
-r|--remote)
LOCAL_CHANGES=false
shift
;;
# With default ubuntu version 20.04
-cv|--cudaversion)
CUDA_VERSION="$2"
Expand Down Expand Up @@ -189,15 +201,15 @@ fi

if [ "${BUILD_TYPE}" == "production" ]
then
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE="${BASE_IMAGE}" --build-arg USE_CUDA_VERSION="${CUDA_VERSION}" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg BUILD_NIGHTLY="${BUILD_NIGHTLY}" -t "${DOCKER_TAG}" --target production-image .
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE="${BASE_IMAGE}" --build-arg USE_CUDA_VERSION="${CUDA_VERSION}" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg BUILD_NIGHTLY="${BUILD_NIGHTLY}" --build-arg BRANCH_NAME="${BRANCH_NAME}" --build-arg BUILD_FROM_SRC="${BUILD_FROM_SRC}" --build-arg LOCAL_CHANGES="${LOCAL_CHANGES}" -t "${DOCKER_TAG}" --target production-image ../
elif [ "${BUILD_TYPE}" == "ci" ]
then
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE="${BASE_IMAGE}" --build-arg USE_CUDA_VERSION="${CUDA_VERSION}" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg BUILD_NIGHTLY="${BUILD_NIGHTLY}" --build-arg BRANCH_NAME="${BRANCH_NAME}" -t "${DOCKER_TAG}" --target ci-image .
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE="${BASE_IMAGE}" --build-arg USE_CUDA_VERSION="${CUDA_VERSION}" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg BUILD_NIGHTLY="${BUILD_NIGHTLY}" --build-arg BRANCH_NAME="${BRANCH_NAME}" --build-arg BUILD_FROM_SRC="${BUILD_FROM_SRC}" --build-arg LOCAL_CHANGES="${LOCAL_CHANGES}" -t "${DOCKER_TAG}" --target ci-image ../
else
if [ "${BUILD_CPP}" == "true" ]
then
DOCKER_BUILDKIT=1 docker build --file Dockerfile.cpp --build-arg BASE_IMAGE="${BASE_IMAGE}" --build-arg USE_CUDA_VERSION="${CUDA_VERSION}" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg BRANCH_NAME="${BRANCH_NAME}" -t "${DOCKER_TAG}" --target cpp-dev-image .
else
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE="${BASE_IMAGE}" --build-arg USE_CUDA_VERSION="${CUDA_VERSION}" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg BUILD_NIGHTLY="${BUILD_NIGHTLY}" --build-arg BRANCH_NAME="${BRANCH_NAME}" --build-arg BUILD_WITH_IPEX="${BUILD_WITH_IPEX}" -t "${DOCKER_TAG}" --target dev-image .
DOCKER_BUILDKIT=1 docker build --file Dockerfile --build-arg BASE_IMAGE="${BASE_IMAGE}" --build-arg USE_CUDA_VERSION="${CUDA_VERSION}" --build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg BUILD_NIGHTLY="${BUILD_NIGHTLY}" --build-arg BRANCH_NAME="${BRANCH_NAME}" --build-arg BUILD_FROM_SRC="${BUILD_FROM_SRC}" --build-arg LOCAL_CHANGES="${LOCAL_CHANGES}" --build-arg BUILD_WITH_IPEX="${BUILD_WITH_IPEX}" -t "${DOCKER_TAG}" --target dev-image ../
fi
fi

0 comments on commit 8450a2e

Please sign in to comment.