Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REPO_URL in Dockerfile to allow docker builds from contributor repos #3291

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ARG BUILD_NIGHTLY
ARG BUILD_FROM_SRC
ARG LOCAL_CHANGES
ARG BRANCH_NAME
ARG REPO_URL=https://github.com/pytorch/serve.git
ENV PYTHONUNBUFFERED TRUE

RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \
Expand Down Expand Up @@ -72,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


Expand Down Expand Up @@ -237,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
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile.neuron.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
29 changes: 25 additions & 4 deletions docker/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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."
Expand All @@ -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"
Expand Down Expand Up @@ -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
Loading