diff --git a/docker/Dockerfile b/docker/Dockerfile index 534aa6a22c..c6edac6657 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 \ @@ -64,7 +67,14 @@ 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" @@ -72,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 \ @@ -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;\ @@ -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 @@ -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 @@ -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" @@ -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"] \ No newline at end of file +CMD ["serve"] diff --git a/docker/README.md b/docker/README.md index 025ad04da4..54d125e34e 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| +|-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 eebadb0b81..f773791784 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=true 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 + ;; + -r|--remote) + LOCAL_CHANGES=false + 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}" -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