This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker_build_ros.sh
executable file
路388 lines (358 loc) 路 14.2 KB
/
docker_build_ros.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/bin/bash
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# reference
# https://gitlab.com/nvidia/container-images/samples/-/blob/main/deployments/container/Makefile
# https://gitlab.com/nvidia/container-images/samples/-/blob/main/deployments/container/Dockerfile.ubuntu
# https://catalog.ngc.nvidia.com/orgs/nvidia/containers/cuda/tags
bold=`tput bold`
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
reset=`tput sgr0`
docker_image_name=rbonghi/isaac-ros-base
BASE_DIST=ubuntu20.04
L4T=35.1
CUDA_VERSION=11.4.1
OPENCV_VERSION=4.5.0
BUILD_BASE=devel
usage()
{
if [ "$1" != "" ]; then
echo "${red}$1${reset}" >&2
fi
local name=$(basename ${0})
echo "$name isaac_ros_base for different architectures." >&2
echo "${bold}Commands:${reset}" >&2
echo " $name help This help" >&2
echo " $name opencv [OPTIONS ...] Build opencv image" >&2
echo " $name devel [OPTIONS ...] Build devel image" >&2
echo " $name runtime [OPTIONS ...] Build runtime image" >&2
echo " $name humble [BASE] [OPTIONS ...] Build ROS2 humble image" >&2
echo " $name gems [OPTIONS ...] Build all Isaac ROS packages in a image" >&2
echo
echo "${bold}BASE:${reset}" >&2
echo " core Ros core packages" >&2
echo " base Ros base packages" >&2
echo "${bold}OPTIONS:${reset}" >&2
echo " --buildx Use docker buildx" >&2
echo " --push Push docker image" >&2
echo " --extract Extract OpenCV tar ball from docker" >&2
echo " --ci Run build in CI (without cash and pull a latest base image)" >&2
echo " --base [NAME] Build from base image. Default: ${bold}$BUILD_BASE${reset}" >&2
echo " --multiarch Build in multiarch (ARM64 and AMD64)" >&2
echo " --l4t Build with L4T Default: L4T=$L4T" >&2
echo " --arm64 Build for arm64 architecture" >&2
echo " --amd64 Build for x86_64 architecture" >&2
echo " --manifest Build and push a manifest to merge two architecture" >&2
}
message_start()
{
local PUSH=$1
local CI=$2
local TAG=$3
# Push message
if $CI ; then
echo " - ${bold}CI${reset} setup"
fi
if $PUSH ; then
echo " - ${bold}BUILD & PUSH${reset} $docker_image_name:$TAG"
else
echo " - ${bold}BUILD${reset} $docker_image_name:$TAG"
fi
}
main()
{
local MULTIARCH=false
local CI_BUILD=false
local PUSH=false
local BUILDX=""
local EXTRACT=false
local MANIFEST=false
# Autoselect mode
local ARCH=$(uname -i)
if [ "$ARCH" == "x86_64" ] ; then
ARCH="amd64"
else
ARCH="arm64"
fi
# Check if run in sudo
if [[ `id -u` -eq 0 ]] ; then
echo "${red}Please don't run as root${reset}" >&2
exit 1
fi
local option=$1
if [ -z "$option" ] ; then
usage
exit 0
fi
local ROS_PKG=""
if [ $option = "humble" ] ; then
case "$2" in
core)
ROS_PKG=core
shift 1
;;
base)
ROS_PKG=base
shift 1
;;
*)
usage "[ERROR] Unknown option: $2" >&2
exit 1
;;
esac
fi
# Load all arguments except the first one
while [ -n "$2" ]; do
case "$2" in
--buildx) # Load help
BUILDX=buildx
;;
--ci)
CI_BUILD=true
;;
--arm64)
ARCH="arm64"
;;
--amd64)
ARCH="amd64"
;;
--l4t)
L4T=$3
shift 1
;;
--base)
BUILD_BASE=$3
shift 1
;;
--multiarch)
MULTIARCH=true
;;
--push)
PUSH=true
;;
--extract)
EXTRACT=true
;;
--manifest)
MANIFEST=true
;;
*)
usage "[ERROR] Unknown option: $2" >&2
exit 1
;;
esac
shift 1
done
# Check if Desktop has GPU
if [ "$ARCH" == "amd64" ] ; then
if type nvidia-smi &>/dev/null; then
local GPU_ATTACHED=(`nvidia-smi -a | grep "Attached GPUs"`)
if [ ! -z $GPU_ATTACHED ]; then
echo "${green}GPU $GPU_ATTACHED${reset}"
else
echo "${red}GPU not attached. Check if driver are installed.${reset}"
exit 1
fi
fi
fi
# Build options for docker
local multiarch_option=""
local push_value=""
local CI_OPTIONS=""
if [ ! -z $BUILDX ] ; then
if $MULTIARCH ; then
multiarch_option="--platform linux/arm64,linux/amd64"
elif [ "$ARCH" == "arm64" ] ; then
multiarch_option="--platform linux/arm64"
elif [ "$ARCH" == "amd64" ] ; then
multiarch_option="--platform linux/amd64"
fi
# Buildx push option
push_value="--push"
else
if $PUSH ; then
push_value="--push"
fi
if $CI_BUILD ; then
# Set no-cache and pull before build
# https://newbedev.com/what-s-the-purpose-of-docker-build-pull
CI_OPTIONS="--no-cache --pull"
fi
fi
# Build tag name
local TAG="$option"
# copy deb packages to jetson-containers/packages directory
if [ $option = "opencv" ] && $EXTRACT ; then
local architecture=$(uname -i)
local OPENCV_PACKAGE="OpenCV-${CUDA_VERSION}-${architecture}.tar.gz"
docker run \
--rm \
--volume $PWD:/mount \
$docker_image_name:opencv-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST} \
cp /opt/opencv/build/$OPENCV_PACKAGE /mount
if $? ; then
echo "${red}Error to run the extraction${reset}"
exit 1
else
echo "OpenCV package is at ${bold}$PWD/$OPENCV_PACKAGE${reset}"
fi
exit 0
fi
# Options
if [ $option = "help" ] || [ $option = "-h" ]; then
usage
exit 0
elif [ $option = "opencv" ] ; then
#### OpenCV #############
message_start $PUSH $CI_BUILD $TAG
echo " - ${bold}OPENCV${reset} image"
echo " - BASE_DIST=${green}$BASE_DIST${reset}"
echo " - L4T=${green}$L4T${reset}"
echo " - CUDA_VERSION=${green}$CUDA_VERSION${reset}"
echo " - OPENCV_VERSION=${green}$OPENCV_VERSION${reset}"
docker ${BUILDX} build \
$push_value \
$CI_OPTIONS \
-t $docker_image_name:opencv-${OPENCV_VERSION} \
-t $docker_image_name:opencv-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T} \
--build-arg BASE_DIST="$BASE_DIST" \
--build-arg L4T="$L4T" \
--build-arg CUDA_VERSION="$CUDA_VERSION" \
--build-arg OPENCV_VERSION="$OPENCV_VERSION" \
$multiarch_option \
-f Dockerfile.opencv \
. || { echo "${red}docker build failure!${reset}"; exit 1; }
exit 0
elif [ $option = "devel" ] || [ $option = "runtime" ] ; then
local TENSORRT_VERSION=8.4
local TRITON_VERSION=2.24.0
if [ $L4T == 35.2 ] ; then
TRITON_VERSION=2.30.0
fi
local L4T_MINOR_VERSION=1.0
if [ $L4T == 35.2 ] ; then
L4T_MINOR_VERSION=2.0
fi
local JETPACK=5.0.2
if [ $L4T == 35.2 ] ; then
JETPACK=5.1
fi
#### DEVEL #############
message_start $PUSH $CI_BUILD $TAG
echo " - ${bold}${option^^}${reset} image"
echo " - BASE_DIST=${green}$BASE_DIST${reset}"
echo " - L4T=${green}$L4T${reset}"
echo " - L4T_MINOR_VERSION=${green}$L4T_MINOR_VERSION${reset}"
echo " - JETPACK=${green}$JETPACK${reset}"
echo " - CUDA_VERSION=${green}$CUDA_VERSION${reset}"
echo " - OPENCV_VERSION=${green}$OPENCV_VERSION${reset}"
echo " - TRITON_VERSION=${green}$TRITON_VERSION${reset}"
echo " - TENSORRT_VERSION=${green}$TENSORRT_VERSION${reset}"
docker ${BUILDX} build \
$push_value \
$CI_OPTIONS \
-t $docker_image_name:$TAG \
-t $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T} \
--build-arg TENSORRT_VERSION="$TENSORRT_VERSION" \
--build-arg TRITON_VERSION="$TRITON_VERSION" \
--build-arg BASE_DIST="$BASE_DIST" \
--build-arg L4T="$L4T" \
--build-arg L4T_MINOR_VERSION="$L4T_MINOR_VERSION" \
--build-arg JETPACK="$JETPACK" \
--build-arg CUDA_VERSION="$CUDA_VERSION" \
--build-arg OPENCV_VERSION="$OPENCV_VERSION" \
$multiarch_option \
-f Dockerfile.$option \
. || { echo "${red}docker build failure!${reset}"; exit 1; }
exit 0
elif [ $option = "humble" ] ; then
# Humble reference
TAG="humble-$ROS_PKG-$BUILD_BASE"
if [ $ROS_PKG = "core" ] ; then
BASE_IMAGE=$docker_image_name:$BUILD_BASE-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}
elif [ $ROS_PKG = "base" ] ; then
BASE_IMAGE=$docker_image_name:humble-core-$BUILD_BASE-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}
else
echo "${red}Error base image!${reset}"
exit 1
fi
#### HUMBLE #############
message_start $PUSH $CI_BUILD $TAG
echo " - ${bold}HUMBLE ${green}${ROS_PKG^^}${reset} image"
echo " - BASE_IMAGE=${green}$BASE_IMAGE${reset}"
echo " - L4T=${green}$L4T${reset}"
docker ${BUILDX} build \
$push_value \
$CI_OPTIONS \
-t $docker_image_name:$TAG \
-t $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T} \
--build-arg BASE_IMAGE="$BASE_IMAGE" \
$multiarch_option \
-f Dockerfile.humble.$ROS_PKG \
. || { echo "${red}docker build failure!${reset}"; exit 1; }
exit 0
elif [ $option = "gems" ] ; then
# tag and image reference
TAG="gems-$BUILD_BASE"
BASE_IMAGE=$docker_image_name:humble-base-$BUILD_BASE-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}
#### Message #############
message_start $PUSH $CI_BUILD $TAG
echo " - ${bold}${option^^}${reset} image"
echo " - BASE_IMAGE=${green}$BASE_IMAGE${reset}"
echo " - L4T=${green}$L4T${reset}"
# Check to build a push a multiplatform manifest
if $MANIFEST ; then
echo "${green}Build and push manifest${reset}"
# Pull images
#docker pull $docker_image_name:$TAG-arm64
#docker pull $docker_image_name:$TAG-amd64
# Create a manifest
docker manifest create $docker_image_name:$TAG --amend $docker_image_name:$TAG-arm64 --amend $docker_image_name:$TAG-amd64
docker manifest annotate --arch arm64 $docker_image_name:$TAG $docker_image_name:$TAG-arm64
docker manifest annotate --arch amd64 $docker_image_name:$TAG $docker_image_name:$TAG-amd64
# Create a manifest
docker manifest create $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T} --amend $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}-arm64 --amend $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}-amd64
docker manifest annotate --arch arm64 $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T} $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}-arm64
docker manifest annotate --arch amd64 $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T} $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}-amd64
# Docker push manifest
docker manifest push $docker_image_name:$TAG
docker manifest push $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}
exit 0
fi
# Otherwise build the image
# Temporary disabled buildx, need fix VPI for x86 architecture
docker build \
$CI_OPTIONS \
-t $docker_image_name:$TAG-$ARCH \
-t $docker_image_name:$TAG-${OPENCV_VERSION}-cuda${CUDA_VERSION}-${BASE_DIST}-L4T${L4T}-$ARCH \
--build-arg BASE_IMAGE="$BASE_IMAGE" \
-f Dockerfile.isaac \
. || { echo "${red}docker build failure!${reset}"; exit 1; }
exit 0
fi
usage "[ERROR] Unknown option: $option" >&2
exit 1
}
main $@
exit 0
# EOF