From af018b17175cd698f3c8e0c1193548d0dd3fb8b3 Mon Sep 17 00:00:00 2001 From: Matthias Reso <13337103+mreso@users.noreply.github.com> Date: Tue, 20 Aug 2024 00:48:02 +0000 Subject: [PATCH 1/4] Add REPO_URL in Dockerfile --- docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 31fad49970..abd4c630c0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -34,6 +34,7 @@ ARG BUILD_NIGHTLY ARG BUILD_FROM_SRC ARG LOCAL_CHANGES ARG BRANCH_NAME +ARG REPO_URL ENV PYTHONUNBUFFERED TRUE RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ From 9fca7b96f3b8bfbac9036ec4b77f11a41ab2f12c Mon Sep 17 00:00:00 2001 From: Matthias Reso <13337103+mreso@users.noreply.github.com> Date: Tue, 20 Aug 2024 01:04:50 +0000 Subject: [PATCH 2/4] Add repo url to docker files and build_image.sh --- docker/Dockerfile | 6 +++--- docker/Dockerfile.cpp | 3 ++- docker/Dockerfile.dev | 3 ++- docker/Dockerfile.neuron.dev | 3 ++- docker/build_image.sh | 29 +++++++++++++++++++++++++---- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index abd4c630c0..71d48f58fe 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -34,7 +34,7 @@ ARG BUILD_NIGHTLY ARG BUILD_FROM_SRC ARG LOCAL_CHANGES ARG BRANCH_NAME -ARG REPO_URL +ARG REPO_URL=https://github.com/pytorch/serve.git ENV PYTHONUNBUFFERED TRUE RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ @@ -73,7 +73,7 @@ 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; \ + git clone --recursive $REPO_URL -b $BRANCH_NAME; \ fi @@ -238,7 +238,7 @@ 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; \ + git clone --recursive $REPO_URL -b $BRANCH_NAME; \ fi COPY --from=compile-image /home/venv /home/venv diff --git a/docker/Dockerfile.cpp b/docker/Dockerfile.cpp index a131bcb9cf..50d19b3322 100644 --- a/docker/Dockerfile.cpp +++ b/docker/Dockerfile.cpp @@ -26,6 +26,7 @@ ARG PYTHON_VERSION ARG CMAKE_VERSION ARG GCC_VERSION ARG BRANCH_NAME +ARG REPO_URL=https://github.com/pytorch/serve.git ARG USE_CUDA_VERSION ARG DEBIAN_FRONTEND=noninteractive ENV PYTHONUNBUFFERED TRUE @@ -67,7 +68,7 @@ RUN (wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/nu && echo "Package: cmake-data\nPin: version $CMAKE_VERSION*\nPin-Priority: 1001" > /etc/apt/preferences.d/cmake-data \ && rm -rf /var/lib/apt/lists/* -RUN git clone --recursive https://github.com/pytorch/serve.git \ +RUN git clone --recursive $REPO_URL \ && cd serve \ && git checkout ${BRANCH_NAME} diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 4a105c815a..2f02d84680 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -16,6 +16,7 @@ FROM ${BASE_IMAGE} AS compile-image ARG BASE_IMAGE ARG BRANCH_NAME=master +ARG REPO_URL=https://github.com/pytorch/serve.git ARG MACHINE_TYPE=cpu ARG CUDA_VERSION @@ -62,7 +63,7 @@ FROM compile-image AS dev-image ARG MACHINE_TYPE=cpu ARG CUDA_VERSION RUN if [ "$MACHINE_TYPE" = "gpu" ]; then export USE_CUDA=1; fi \ - && git clone https://github.com/pytorch/serve.git \ + && git clone $REPO_URL \ && cd serve \ && git checkout ${BRANCH_NAME} \ && python$PYTHON_VERSION -m venv /home/venv diff --git a/docker/Dockerfile.neuron.dev b/docker/Dockerfile.neuron.dev index 7c12ee13c5..cd861e1fbe 100644 --- a/docker/Dockerfile.neuron.dev +++ b/docker/Dockerfile.neuron.dev @@ -21,6 +21,7 @@ FROM ${BASE_IMAGE} AS compile-image ARG BASE_IMAGE ARG BRANCH_NAME=master +ARG REPO_URL=https://github.com/pytorch/serve.git ARG MACHINE_TYPE=cpu ARG CUDA_VERSION @@ -67,7 +68,7 @@ FROM compile-image AS dev-image ARG MACHINE_TYPE=cpu ARG CUDA_VERSION RUN if [ "$MACHINE_TYPE" = "gpu" ]; then export USE_CUDA=1; fi \ - && git clone https://github.com/pytorch/serve.git \ + && git clone $REPO_URL \ && cd serve \ && git checkout --track ${BRANCH_NAME} \ && if [ -z "$CUDA_VERSION" ]; then python ts_scripts/install_dependencies.py --environment=dev; else python ts_scripts/install_dependencies.py --environment=dev --cuda $CUDA_VERSION; fi \ diff --git a/docker/build_image.sh b/docker/build_image.sh index 4738021a8a..650215a492 100755 --- a/docker/build_image.sh +++ b/docker/build_image.sh @@ -4,6 +4,7 @@ set -o errexit -o nounset -o pipefail MACHINE=cpu BRANCH_NAME="master" +REPO_URL="https://github.com/pytorch/serve.git" DOCKER_TAG="pytorch/torchserve:latest-cpu" BUILD_TYPE="production" BASE_IMAGE="ubuntu:20.04" @@ -25,6 +26,7 @@ do echo "options:" echo "-h, --help show brief help" echo "-b, --branch_name=BRANCH_NAME specify a branch_name to use" + echo "-repo, --repo_url=REPO_URL specify a github repo url to use" echo "-g, --gpu specify to use gpu" echo "-bi, --baseimage specify base docker image. Example: nvidia/cuda:11.7.0-cudnn8-runtime-ubuntu20.04 " echo "-bt, --buildtype specify for type of created image. Possible values: production, dev, ci." @@ -51,6 +53,18 @@ do fi shift ;; + -repo|--repo_url) + if test $ + then + REPO_URL="$2" + LOCAL_CHANGES=false + shift + else + echo "Error! repo_url not provided" + exit 1 + fi + shift + ;; -g|--gpu) MACHINE=gpu DOCKER_TAG="pytorch/torchserve:latest-gpu" @@ -202,15 +216,22 @@ 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}" --build-arg BUILD_FROM_SRC="${BUILD_FROM_SRC}" --build-arg LOCAL_CHANGES="${LOCAL_CHANGES}" -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 REPO_URL="${REPO_URL}" --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}" --build-arg BUILD_FROM_SRC="${BUILD_FROM_SRC}" --build-arg LOCAL_CHANGES="${LOCAL_CHANGES}" -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 REPO_URL="${REPO_URL}" --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 . + 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}" --build-arg REPO_URL="${REPO_URL}" -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_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 ../ + 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 REPO_URL="${REPO_URL}" --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 59f4fa9311ca5b7e0d0a01ebbb4ee7a2a8661e3f Mon Sep 17 00:00:00 2001 From: Matthias Reso <13337103+mreso@users.noreply.github.com> Date: Tue, 20 Aug 2024 01:07:45 +0000 Subject: [PATCH 3/4] Enable repo url in docker ci workflow --- .github/workflows/docker-ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-ci.yaml b/.github/workflows/docker-ci.yaml index 0e7db91825..f4882170ed 100644 --- a/.github/workflows/docker-ci.yaml +++ b/.github/workflows/docker-ci.yaml @@ -39,7 +39,7 @@ jobs: working-directory: docker run: | IMAGE_TAG=test-image-${{ matrix.python-version }} - ./build_image.sh -py "${{ matrix.python-version }}" -t "${IMAGE_TAG}" -b ${{ steps.branch-name.outputs.GITHUB_BRANCH }} -s + ./build_image.sh -py "${{ matrix.python-version }}" -t "${IMAGE_TAG}" -b ${{ steps.branch-name.outputs.GITHUB_BRANCH }} -repo ${{ github.repositoryUrl }} -s echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT - name: Container Healthcheck From 6ecc10c2df4ca1a71be7cbdfb72627b45a3f8bd6 Mon Sep 17 00:00:00 2001 From: Matthias Reso <13337103+mreso@users.noreply.github.com> Date: Tue, 20 Aug 2024 03:39:43 +0000 Subject: [PATCH 4/4] Update docs for repo url --- docker/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/README.md b/docker/README.md index 64a22ca90c..beb0604e10 100644 --- a/docker/README.md +++ b/docker/README.md @@ -38,6 +38,7 @@ Use `build_image.sh` script to build the docker images. The script builds the `p |------|------| |-h, --help|Show script help| |-b, --branch_name|Specify a branch name to use. Default: master | +|-repo, --repo_url|Specify the repository url to use. Default: https://github.com/pytorch/serve | |-g, --gpu|Build image with GPU based ubuntu base image| |-bi, --baseimage specify base docker image. Example: nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04| |-bt, --buildtype|Which type of docker image to build. Can be one of : production, dev, ci|