Skip to content

Commit 8450a2e

Browse files
authored
Install from source for a specific branch with docker (#3055)
* 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
1 parent 4f90708 commit 8450a2e

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

docker/Dockerfile

+31-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ FROM ${BASE_IMAGE} AS compile-image
3131
ARG BASE_IMAGE=ubuntu:rolling
3232
ARG PYTHON_VERSION
3333
ARG BUILD_NIGHTLY
34+
ARG BUILD_FROM_SRC
35+
ARG LOCAL_CHANGES
36+
ARG BRANCH_NAME
3437
ENV PYTHONUNBUFFERED TRUE
3538

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

6568
ARG USE_CUDA_VERSION=""
6669

67-
RUN git clone --depth 1 --recursive https://github.com/pytorch/serve.git
70+
COPY ./ serve
71+
72+
RUN \
73+
if echo "$LOCAL_CHANGES" | grep -q "false"; then \
74+
rm -rf serve;\
75+
git clone --recursive https://github.com/pytorch/serve.git -b $BRANCH_NAME; \
76+
fi
77+
6878

6979
WORKDIR "serve"
7080

7181
RUN \
7282
if echo "$BASE_IMAGE" | grep -q "cuda:"; then \
7383
# Install CUDA version specific binary when CUDA version is specified as a build arg
7484
if [ "$USE_CUDA_VERSION" ]; then \
75-
python ./ts_scripts/install_dependencies.py --cuda $USE_CUDA_VERSION; \
85+
python ./ts_scripts/install_dependencies.py --cuda $USE_CUDA_VERSION;\
7686
# Install the binary with the latest CPU image on a CUDA base image
7787
else \
78-
python ./ts_scripts/install_dependencies.py; \
88+
python ./ts_scripts/install_dependencies.py;\
7989
fi; \
8090
# Install the CPU binary
8191
else \
@@ -84,7 +94,10 @@ RUN \
8494

8595
# Make sure latest version of torchserve is uploaded before running this
8696
RUN \
87-
if echo "$BUILD_NIGHTLY" | grep -q "false"; then \
97+
if echo "$BUILD_FROM_SRC" | grep -q "true"; then \
98+
python -m pip install -r requirements/developer.txt;\
99+
python ts_scripts/install_from_src.py;\
100+
elif echo "$BUILD_NIGHTLY" | grep -q "false"; then \
88101
python -m pip install --no-cache-dir torchserve torch-model-archiver torch-workflow-archiver;\
89102
else \
90103
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
121134

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

124-
COPY dockerd-entrypoint.sh /usr/local/bin/dockerd-entrypoint.sh
137+
COPY docker/dockerd-entrypoint.sh /usr/local/bin/dockerd-entrypoint.sh
125138

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

129-
COPY config.properties /home/model-server/config.properties
142+
COPY docker/config.properties /home/model-server/config.properties
130143
RUN mkdir /home/model-server/model-store && chown -R model-server /home/model-server/model-store
131144

132145
EXPOSE 8080 8081 8082 7070 7071
@@ -187,6 +200,8 @@ FROM ${BASE_IMAGE} as dev-image
187200
# Re-state ARG PYTHON_VERSION to make it active in this build-stage (uses default define at the top)
188201
ARG PYTHON_VERSION
189202
ARG BRANCH_NAME
203+
ARG BUILD_FROM_SRC
204+
ARG LOCAL_CHANGES
190205
ARG BUILD_WITH_IPEX
191206
ARG IPEX_VERSION=1.11.0
192207
ARG IPEX_URL=https://software.intel.com/ipex-whl-stable
@@ -216,9 +231,15 @@ RUN --mount=type=cache,target=/var/cache/apt \
216231
numactl \
217232
&& 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 \
218233
&& rm -rf /var/lib/apt/lists/*
219-
RUN git clone --recursive https://github.com/pytorch/serve.git \
220-
&& cd serve \
221-
&& git checkout ${BRANCH_NAME}
234+
235+
COPY ./ serve
236+
237+
RUN \
238+
if echo "$LOCAL_CHANGES" | grep -q "false"; then \
239+
rm -rf serve;\
240+
git clone --recursive https://github.com/pytorch/serve.git -b $BRANCH_NAME; \
241+
fi
242+
222243
COPY --from=compile-image /home/venv /home/venv
223244
ENV PATH="/home/venv/bin:$PATH"
224245
WORKDIR "serve"
@@ -238,4 +259,4 @@ USER model-server
238259
WORKDIR /home/model-server
239260
ENV TEMP=/home/model-server/tmp
240261
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh"]
241-
CMD ["serve"]
262+
CMD ["serve"]

docker/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Use `build_image.sh` script to build the docker images. The script builds the `p
4343
|-ipex, --build-with-ipex| Specify to build with intel_extension_for_pytorch. If not specified, script builds without intel_extension_for_pytorch.|
4444
|-cpp, --build-cpp specify to build TorchServe CPP|
4545
|-n, --nightly| Specify to build with TorchServe nightly.|
46+
|-s, --source| Specify to build with TorchServe from source|
47+
|-r, --remote| Specify to use github remote repo|
4648
|-py, --pythonversion| Specify the python version to use. Supported values `3.8`, `3.9`, `3.10`, `3.11`. Default `3.9`|
4749

4850

docker/build_image.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ USE_LOCAL_SERVE_FOLDER=false
1414
BUILD_WITH_IPEX=false
1515
BUILD_CPP=false
1616
BUILD_NIGHTLY=false
17+
BUILD_FROM_SRC=false
18+
LOCAL_CHANGES=true
1719
PYTHON_VERSION=3.9
1820

1921
for arg in "$@"
@@ -33,6 +35,8 @@ do
3335
echo "-cpp, --build-cpp specify to build TorchServe CPP"
3436
echo "-py, --pythonversion specify to python version to use: Possible values: 3.8 3.9 3.10"
3537
echo "-n, --nightly specify to build with TorchServe nightly"
38+
echo "-s, --source specify to build with TorchServe from source"
39+
echo "-l, --local specify to use local TorchServe"
3640
exit 0
3741
;;
3842
-b|--branch_name)
@@ -97,6 +101,14 @@ do
97101
shift
98102
shift
99103
;;
104+
-s|--source)
105+
BUILD_FROM_SRC=true
106+
shift
107+
;;
108+
-r|--remote)
109+
LOCAL_CHANGES=false
110+
shift
111+
;;
100112
# With default ubuntu version 20.04
101113
-cv|--cudaversion)
102114
CUDA_VERSION="$2"
@@ -189,15 +201,15 @@ fi
189201

190202
if [ "${BUILD_TYPE}" == "production" ]
191203
then
192-
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 .
204+
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 ../
193205
elif [ "${BUILD_TYPE}" == "ci" ]
194206
then
195-
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 .
207+
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 ../
196208
else
197209
if [ "${BUILD_CPP}" == "true" ]
198210
then
199211
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 .
200212
else
201-
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 .
213+
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 ../
202214
fi
203215
fi

0 commit comments

Comments
 (0)