forked from dusty-nv/jetson-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_build_ros.sh
executable file
·194 lines (168 loc) · 5.77 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
#!/usr/bin/env bash
#
# Builds ROS container(s) by installing packages or from source (when needed)
# See help text below or run './scripts/docker_build_ros.sh --help' for options
#
set -e
show_help() {
echo " "
echo "usage: Builds various ROS Docker containers for Jetson / JetPack-L4T"
echo " "
echo " ./scripts/docker_build_ros.sh --distro DISTRO"
echo " --package PACKAGE"
echo " --with-pytorch"
echo " --with-slam"
echo " "
echo "args:"
echo " "
echo " --help Show this help text and quit"
echo " "
echo " --distro DISTRO Specifies the ROS distro to build, one of:"
echo " 'melodic', 'noetic', 'eloquent', 'foxy', 'galactic'"
echo " Or the default of 'all' will build all distros."
echo " "
echo " --package PKG Specifies the ROS meta-package to install, one of:"
echo " 'ros_base', 'ros_core', 'desktop', 'all'"
echo " The default is 'ros_base'. Note that 'desktop' may"
echo " have issues on some distros that are built from source."
echo " "
echo " --with-pytorch Builds additional container with PyTorch support."
echo " This only applies to noetic, foxy, and galactic."
echo " "
echo " --with-slam Builds additional container with VSLAM packages,"
echo " including ORBSLAM2, RTABMAP, ZED, and Realsense."
echo " This only applies to foxy and galactic and implies"
echo " --with-pytorch as these containers use PyTorch."
echo " "
}
die() {
printf '%s\n' "$1"
show_help
exit 1
}
# determine the L4T version
source scripts/docker_base.sh
source scripts/opencv_version.sh
# define default options
if [[ $L4T_RELEASE -eq 34 ]]; then # JetPack 5.x / Ubuntu 20.04
SUPPORTED_ROS_DISTROS=("noetic" "foxy" "galactic" "humble")
else
SUPPORTED_ROS_DISTROS=("melodic" "noetic" "eloquent" "foxy" "galactic" "humble")
fi
SUPPORTED_ROS_PACKAGES=("ros_base" "ros_core" "desktop")
ROS_DISTRO="all"
ROS_PACKAGE="ros_base"
WITH_PYTORCH="off"
WITH_SLAM="off"
# parse options
while :; do
case $1 in
-h|-\?|--help)
show_help
exit
;;
--distro) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
ROS_DISTRO=$2
shift
else
die 'ERROR: "--distro" requires a non-empty option argument.'
fi
;;
--distro=?*)
ROS_DISTRO=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--distror=) # Handle the case of an empty --distro=
die 'ERROR: "--distro" requires a non-empty option argument.'
;;
--package)
if [ "$2" ]; then
ROS_PACKAGE=$2
shift
else
die 'ERROR: "--package" requires a non-empty option argument.'
fi
;;
--package=?*)
ROS_PACKAGE=${1#*=}
;;
--package=) # Handle the case of an empty --distro=
die 'ERROR: "--package" requires a non-empty option argument.'
;;
--with-pytorch)
WITH_PYTORCH="on"
;;
--with-slam)
WITH_PYTORCH="on"
WITH_SLAM="on"
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
echo "ROS_DISTRO: $ROS_DISTRO"
echo "ROS_PACKAGE: $ROS_PACKAGE"
echo "WITH_PYTORCH: $WITH_PYTORCH"
echo "WITH_SLAM: $WITH_SLAM"
if [[ "$ROS_DISTRO" == "all" ]]; then
BUILD_DISTRO=${SUPPORTED_ROS_DISTROS[@]}
else
BUILD_DISTRO=($ROS_DISTRO)
fi
if [[ "$ROS_PACKAGE" == "all" ]]; then
BUILD_PACKAGES=${SUPPORTED_ROS_PACKAGES[@]}
else
BUILD_PACKAGES=($ROS_PACKAGE)
if [[ ! " ${SUPPORTED_ROS_PACKAGES[@]} " =~ " ${ROS_PACKAGE} " ]]; then
echo "error -- '$ROS_PACKAGE' isn't one of the supported ROS packages:"
echo " ${SUPPORTED_ROS_PACKAGES[@]}"
exit 1
fi
fi
# check for local version of PyTorch base container
BASE_IMAGE_PYTORCH="jetson-inference:r$L4T_VERSION"
if [[ "$(sudo docker images -q $BASE_IMAGE_PYTORCH 2> /dev/null)" == "" ]]; then
BASE_IMAGE_PYTORCH="dustynv/$BASE_IMAGE_PYTORCH"
fi
build_ros()
{
local distro=$1
local package=$2
local base_image=$3
local extra_tag=$4
local dockerfile=${5:-"Dockerfile.ros.$distro"}
local container_tag="ros:${distro}-${extra_tag}l4t-r${L4T_VERSION}"
echo ""
echo "Building container $container_tag"
echo "BASE_IMAGE=$base_image"
echo ""
sh ./scripts/docker_build.sh $container_tag $dockerfile \
--build-arg ROS_PKG=$package \
--build-arg BASE_IMAGE=$base_image \
--build-arg OPENCV_URL=$OPENCV_URL \
--build-arg OPENCV_DEB=$OPENCV_DEB
# restore opencv.csv mounts
if [ -f "$CV_CSV.backup" ]; then
sudo mv $CV_CSV.backup $CV_CSV
fi
}
for DISTRO in ${BUILD_DISTRO[@]}; do
for PACKAGE in ${BUILD_PACKAGES[@]}; do
build_ros $DISTRO $PACKAGE $BASE_IMAGE "`echo $PACKAGE | tr '_' '-'`-"
if [[ "$WITH_PYTORCH" == "on" && "$DISTRO" != "melodic" && "$DISTRO" != "eloquent" ]]; then
build_ros $DISTRO $PACKAGE $BASE_IMAGE_PYTORCH "pytorch-"
fi
if [[ "$WITH_SLAM" == "on" && ("$DISTRO" == "foxy" || "$DISTRO" == "galactic") ]]; then
BASE_IMAGE_SLAM="ros:$DISTRO-pytorch-l4t-r$L4T_VERSION"
build_ros $DISTRO $PACKAGE $BASE_IMAGE_SLAM "slam-" "Dockerfile.ros.slam"
fi
done
done