From f6e6833d8b4b88d8d2258198707f8c7246cae272 Mon Sep 17 00:00:00 2001 From: agunapal Date: Fri, 29 Mar 2024 19:11:22 +0000 Subject: [PATCH 1/3] install from source for a specific branch --- docker/Dockerfile | 10 +++++++--- docker/build_image.sh | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 534aa6a22c..a1f0235dfb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -31,6 +31,7 @@ FROM ${BASE_IMAGE} AS compile-image ARG BASE_IMAGE=ubuntu:rolling ARG PYTHON_VERSION ARG BUILD_NIGHTLY +ARG BRANCH_NAME ENV PYTHONUNBUFFERED TRUE RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ @@ -64,7 +65,7 @@ RUN export USE_CUDA=1 ARG USE_CUDA_VERSION="" -RUN git clone --depth 1 --recursive https://github.com/pytorch/serve.git +RUN git clone --recursive https://github.com/pytorch/serve.git -b $BRANCH_NAME WORKDIR "serve" @@ -84,7 +85,10 @@ RUN \ # Make sure latest version of torchserve is uploaded before running this RUN \ - if echo "$BUILD_NIGHTLY" | grep -q "false"; then \ + if [ "$BRANCH_NAME" != "master" ]; 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;\ @@ -238,4 +242,4 @@ USER model-server WORKDIR /home/model-server ENV TEMP=/home/model-server/tmp ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh"] -CMD ["serve"] \ No newline at end of file +CMD ["serve"] diff --git a/docker/build_image.sh b/docker/build_image.sh index eebadb0b81..2b8cc6bd84 100755 --- a/docker/build_image.sh +++ b/docker/build_image.sh @@ -189,7 +189,7 @@ 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}" -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 . From 77672bb6fe01c9b1409865c6110bbe2aa0298155 Mon Sep 17 00:00:00 2001 From: agunapal Date: Fri, 5 Apr 2024 22:05:02 +0000 Subject: [PATCH 2/3] Build docker images with local changes and TS from source --- docker/Dockerfile | 35 ++++++++++++++++++++++++++--------- docker/README.md | 2 ++ docker/build_image.sh | 18 +++++++++++++++--- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index a1f0235dfb..c6edac6657 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -31,6 +31,8 @@ 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 @@ -65,7 +67,14 @@ RUN export USE_CUDA=1 ARG USE_CUDA_VERSION="" -RUN git clone --recursive https://github.com/pytorch/serve.git -b $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 + WORKDIR "serve" @@ -73,10 +82,10 @@ 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 \ @@ -85,7 +94,7 @@ RUN \ # Make sure latest version of torchserve is uploaded before running this RUN \ - if [ "$BRANCH_NAME" != "master" ]; 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 \ @@ -125,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 @@ -191,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 @@ -220,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" diff --git a/docker/README.md b/docker/README.md index 025ad04da4..5d8e269f50 100644 --- a/docker/README.md +++ b/docker/README.md @@ -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| +|-l, --local| Specify to use local changes| |-py, --pythonversion| Specify the python version to use. Supported values `3.8`, `3.9`, `3.10`, `3.11`. Default `3.9`| diff --git a/docker/build_image.sh b/docker/build_image.sh index 2b8cc6bd84..8e55c5fcde 100755 --- a/docker/build_image.sh +++ b/docker/build_image.sh @@ -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=false PYTHON_VERSION=3.9 for arg in "$@" @@ -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) @@ -97,6 +101,14 @@ do shift shift ;; + -s|--source) + BUILD_FROM_SRC=true + shift + ;; + -l|--local) + LOCAL_CHANGES=true + shift + ;; # With default ubuntu version 20.04 -cv|--cudaversion) CUDA_VERSION="$2" @@ -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}" --build-arg BRANCH_NAME="${BRANCH_NAME}" -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 From b0ae37dc1210478109d5af53cedf49c6e004cc54 Mon Sep 17 00:00:00 2001 From: agunapal Date: Fri, 5 Apr 2024 23:29:05 +0000 Subject: [PATCH 3/3] Use local changes by default. Switched the local option to remote --- docker/README.md | 2 +- docker/build_image.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/README.md b/docker/README.md index 5d8e269f50..54d125e34e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -44,7 +44,7 @@ Use `build_image.sh` script to build the docker images. The script builds the `p |-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| -|-l, --local| Specify to use local changes| +|-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`| diff --git a/docker/build_image.sh b/docker/build_image.sh index 8e55c5fcde..f773791784 100755 --- a/docker/build_image.sh +++ b/docker/build_image.sh @@ -15,7 +15,7 @@ BUILD_WITH_IPEX=false BUILD_CPP=false BUILD_NIGHTLY=false BUILD_FROM_SRC=false -LOCAL_CHANGES=false +LOCAL_CHANGES=true PYTHON_VERSION=3.9 for arg in "$@" @@ -105,8 +105,8 @@ do BUILD_FROM_SRC=true shift ;; - -l|--local) - LOCAL_CHANGES=true + -r|--remote) + LOCAL_CHANGES=false shift ;; # With default ubuntu version 20.04