forked from dusty-nv/jetson-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_build_ros.sh
executable file
·179 lines (154 loc) · 5.05 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
#!/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 " "
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 " "
}
die() {
printf '%s\n' "$1"
show_help
exit 1
}
# determine the L4T version
source scripts/docker_base.sh
source scripts/opencv_version.sh
source scripts/ros_distro.sh
# define default build options
SUPPORTED_ROS_PACKAGES=("ros_base" "ros_core" "desktop")
ROS_DISTRO="all"
ROS_PACKAGE="ros_base"
WITH_PYTORCH="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.
;;
--distro=) # 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"
;;
--) # 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"
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="Dockerfile.ros2"
if [[ $distro == "melodic" || $distro == "noetic" ]]; then
dockerfile="Dockerfile.ros.$distro"
fi
dockerfile=${5:-"$dockerfile"}
local container_tag="ros:${distro}-${extra_tag}l4t-r${L4T_VERSION}"
echo ""
echo "Building container $container_tag"
echo "BASE_IMAGE=$base_image"
echo "DOCKERFILE=$dockerfile"
echo ""
bash ./scripts/docker_build.sh $container_tag $dockerfile \
--build-arg ROS_PKG=$package \
--build-arg ROS_VERSION=$distro \
--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
done
done