-
Notifications
You must be signed in to change notification settings - Fork 860
/
build_image.sh
executable file
·248 lines (238 loc) · 8.62 KB
/
build_image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
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"
UPDATE_BASE_IMAGE=false
USE_CUSTOM_TAG=false
CUDA_VERSION=""
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
ARCH="linux/arm64,linux/amd64"
MULTI=false
for arg in "$@"
do
case $arg in
-h|--help)
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."
echo "-cv, --cudaversion specify to cuda version to use"
echo "-t, --tag specify tag name for docker image"
echo "-lf, --use-local-serve-folder specify this option for the benchmark image if the current 'serve' folder should be used during automated benchmarks"
echo "-ipex, --build-with-ipex specify to build with intel_extension_for_pytorch"
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 "-r, --remote specify to use local TorchServe"
exit 0
;;
-b|--branch_name)
if test $
then
BRANCH_NAME="$2"
LOCAL_CHANGES=false
shift
else
echo "Error! branch_name not provided"
exit 1
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"
BASE_IMAGE="nvidia/cuda:12.1.1-base-ubuntu20.04"
CUDA_VERSION="cu121"
shift
;;
-bi|--baseimage)
BASE_IMAGE="$2"
UPDATE_BASE_IMAGE=true
shift
shift
;;
-bt|--buildtype)
BUILD_TYPE="$2"
shift
shift
;;
-t|--tag)
CUSTOM_TAG="$2"
USE_CUSTOM_TAG=true
shift
shift
;;
-lf|--use-local-serve-folder)
USE_LOCAL_SERVE_FOLDER=true
shift
;;
-ipex|--build-with-ipex)
BUILD_WITH_IPEX=true
shift
;;
-cpp|--build-cpp)
BUILD_CPP=true
shift
;;
-m|--multi)
MULTI=true
shift
;;
-n|--nightly)
BUILD_NIGHTLY=true
shift
;;
-py|--pythonversion)
PYTHON_VERSION="$2"
if [[ $PYTHON_VERSION = 3.8 || $PYTHON_VERSION = 3.9 || $PYTHON_VERSION = 3.10 || $PYTHON_VERSION = 3.11 ]]; then
echo "Valid python version"
else
echo "Valid python versions are 3.8, 3.9 3.10 and 3.11"
exit 1
fi
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"
if [ "${CUDA_VERSION}" == "cu121" ];
then
BASE_IMAGE="nvidia/cuda:12.1.0-base-ubuntu20.04"
elif [ "${CUDA_VERSION}" == "cu118" ];
then
BASE_IMAGE="nvidia/cuda:11.8.0-base-ubuntu20.04"
elif [ "${CUDA_VERSION}" == "cu117" ];
then
BASE_IMAGE="nvidia/cuda:11.7.1-base-ubuntu20.04"
elif [ "${CUDA_VERSION}" == "cu116" ];
then
BASE_IMAGE="nvidia/cuda:11.6.0-cudnn8-runtime-ubuntu20.04"
elif [ "${CUDA_VERSION}" == "cu113" ];
then
BASE_IMAGE="nvidia/cuda:11.3.0-cudnn8-runtime-ubuntu20.04"
elif [ "${CUDA_VERSION}" == "cu111" ];
then
BASE_IMAGE="nvidia/cuda:11.1.1-cudnn8-runtime-ubuntu20.04"
elif [ "${CUDA_VERSION}" == "cu102" ];
then
BASE_IMAGE="nvidia/cuda:10.2-cudnn8-runtime-ubuntu18.04"
elif [ "${CUDA_VERSION}" == "cu101" ]
then
BASE_IMAGE="nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04"
elif [ "${CUDA_VERSION}" == "cu92" ];
then
BASE_IMAGE="nvidia/cuda:9.2-cudnn7-runtime-ubuntu18.04"
else
echo "CUDA version not supported"
exit 1
fi
shift
shift
;;
esac
done
if [ "${MACHINE}" == "gpu" ] && $BUILD_WITH_IPEX ;
then
echo "--gpu and --ipex are mutually exclusive. Please select one of them."
exit 1
fi
if [ "${BUILD_TYPE}" == "dev" ] && ! $USE_CUSTOM_TAG ;
then
if [ "${BUILD_CPP}" == "true" ]
then
DOCKER_TAG="pytorch/torchserve:cpp-dev-$MACHINE"
else
DOCKER_TAG="pytorch/torchserve:dev-$MACHINE"
fi
fi
if [ "$USE_CUSTOM_TAG" = true ]
then
DOCKER_TAG=${CUSTOM_TAG}
fi
if [[ $UPDATE_BASE_IMAGE == true && $MACHINE == "gpu" ]];
then
echo "Incompatible options: -bi doesn't work with -g option"
exit 1
fi
if [ "$BUILD_CPP" == "true" ];
then
if [ "$BUILD_TYPE" != "dev" ];
then
echo "Only dev container build is supported for CPP"
exit 1
fi
if [[ "${MACHINE}" == "gpu" || "${CUDA_VERSION}" != "" ]];
then
if [ "${CUDA_VERSION}" == "cu121" ];
then
BASE_IMAGE="nvidia/cuda:12.1.1-devel-ubuntu20.04"
elif [ "${CUDA_VERSION}" == "cu118" ];
then
BASE_IMAGE="nvidia/cuda:11.8.0-devel-ubuntu20.04"
else
echo "Cuda version $CUDA_VERSION is not supported for CPP"
exit 1
fi
fi
fi
if [ "${BUILD_TYPE}" == "production" ]; then
if [ "${MULTI}" == "true" ]; then
DOCKER_BUILDKIT=1 docker buildx 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}" --platform "${ARCH}" --target production-image ../ --push
else
DOCKER_BUILDKIT=1 docker buildx 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 ../ --load
fi
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 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}" --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 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