-
Notifications
You must be signed in to change notification settings - Fork 1
/
prebuild_docker.sh
executable file
·222 lines (190 loc) · 5.83 KB
/
prebuild_docker.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
#!/bin/bash
# Copyright (c) 2020, 2023 Carnegie Mellon University, IBM Corporation, and others
#
# 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.
## termination hook
trap ctrl_c INT QUIT TERM
function ctrl_c() {
exit
}
function red {
echo -en "\033[31m" ## red
echo $1
echo -en "\033[0m" ## reset color
}
function blue {
echo -en "\033[36m" ## blue
echo $1
echo -en "\033[0m" ## reset color
}
function help {
echo "Usage: $0 -p <prefix>"
echo ""
echo "-h show this help"
echo "-o <option> prebuild with option"
echo "-P <prefix> prebuild with prefix"
}
ROS2_UBUNTUV=22.04
ROS2_UBUNTU_DISTRO=jammy
ROS2_DISTRO=humble
pwd=$(pwd)
scriptdir=$(dirname $0)
cd $scriptdir
scriptdir=$(pwd)
build_dir=$scriptdir/docker
prefix=
option="--progress=auto"
while getopts "ho:P:" arg; do
case $arg in
h)
help
exit
;;
o)
option=$OPTARG
;;
P)
prefix=${OPTARG}
;;
esac
done
shift $((OPTIND-1))
if [[ -z $prefix ]]; then
help
exit 1
fi
function build_ros_base_image {
local FROM_IMAGE=$1
local IMAGE_TAG_PREFIX=$2
local UBUNTU_DISTRO=$3
local ROS_DISTRO=$4
local ROS_COMPONENT=$5
local -n IMAGE_TAG=$6
echo ""
IMAGE_TAG=$IMAGE_TAG_PREFIX-$ROS_DISTRO
blue "## build $IMAGE_TAG"
pushd $build_dir/docker_images/ros/$ROS_DISTRO/ubuntu/$UBUNTU_DISTRO/ros-core/
sed s=FROM.*=FROM\ $FROM_IMAGE= Dockerfile > Dockerfile.temp && \
docker build -f Dockerfile.temp -t $IMAGE_TAG $option .
rm Dockerfile.temp
if [ $? -ne 0 ]; then
red "failed to build $IMAGE_TAG"
exit 1
fi
popd
echo ""
FROM_IMAGE=$IMAGE_TAG
IMAGE_TAG=$IMAGE_TAG_PREFIX-$ROS_DISTRO-base
blue "## build $IMAGE_TAG"
pushd $build_dir/docker_images/ros/$ROS_DISTRO/ubuntu/$UBUNTU_DISTRO/ros-base/
sed s=FROM.*=FROM\ $FROM_IMAGE= Dockerfile > Dockerfile.temp && \
docker build -f Dockerfile.temp -t $IMAGE_TAG $option .
rm Dockerfile.temp
if [ $? -ne 0 ]; then
red "failed to build $IMAGE_TAG"
exit 1
fi
popd
if [[ $ROS_COMPONENT = "ros-base" ]]; then
returnn
fi
echo ""
IMAGE_TAG=$IMAGE_TAG_PREFIX-$ROS_DISTRO-desktop
blue "## build $IMAGE_TAG"
pushd $build_dir/docker_images/ros/$ROS_DISTRO/ubuntu/$UBUNTU_DISTRO/desktop/
sed s=FROM.*=FROM\ $FROM_IMAGE= Dockerfile > Dockerfile.temp && \
docker build -f Dockerfile.temp -t $IMAGE_TAG $option .
rm Dockerfile.temp
if [ $? -ne 0 ]; then
red "failed to build $IMAGE_TAG"
exit 1
fi
popd
}
function prebuild_x86_64 {
local FROM_IMAGE=$1
local IMAGE_BASE_NAME=$2
local IMAGE_DIR=$3
local -n IMAGE_TAG=$4 # output variable name
IMAGE_TAG=$IMAGE_BASE_NAME-$(basename $IMAGE_DIR)
pushd $IMAGE_DIR
blue "## build $IMAGE_TAG"
docker build -t $IMAGE_TAG \
--file Dockerfile \
--build-arg FROM_IMAGE=$FROM_IMAGE \
. && popd
}
function prebuild_ros2_x86_64 {
blue "- UBUNTU_DISTRO=$ROS2_UBUNTU_DISTRO"
blue "- ROS2_DISTRO=$ROS2_DISTRO"
base_image=ubuntu:$ROS2_UBUNTU_DISTRO
base_name=${prefix}__${ROS2_UBUNTU_DISTRO}
image_tag=$base_image
build_ros_base_image $image_tag $image_tag $ROS2_UBUNTU_DISTRO $ROS2_DISTRO desktop image_tag
if [ $? -ne 0 ]; then
red "failed to build $name1"
exit 1
fi
prebuild_x86_64 $image_tag $base_name $build_dir/${ROS2_DISTRO}-custom image_tag
if [ $? -ne 0 ]; then
red "failed to build $image_tag"
return 1
fi
prebuild_x86_64 $image_tag $image_tag $build_dir/mesa image_tag
if [ $? -ne 0 ]; then
red "failed to build $image_tag"
return 1
fi
}
function prebuild_aarch64 {
local FROM_IMAGE=$1
local IMAGE_BASE_NAME=$2
local IMAGE_DIR=$3
local -n IMAGE_TAG=$4 # output variable name
IMAGE_TAG=$IMAGE_BASE_NAME-$(basename $IMAGE_DIR)
pushd $IMAGE_DIR
blue "## build $IMAGE_TAG"
docker build -t $IMAGE_TAG \
--file Dockerfile.jetson \
--build-arg FROM_IMAGE=$FROM_IMAGE \
. && popd
}
function prebuild_ros2_aarch64 {
blue "- UBUNTU_DISTRO=$ROS2_UBUNTU_DISTRO"
blue "- ROS2_DISTRO=$ROS2_DISTRO"
base_image="nvcr.io/nvidia/l4t-base:r36.2.0"
base_name=${prefix}__${ROS2_UBUNTU_DISTRO}
image_tag=$base_image
build_ros_base_image $image_tag $image_tag $ROS2_UBUNTU_DISTRO $ROS2_DISTRO desktop image_tag
if [ $? -ne 0 ]; then
red "failed to build $name1"
exit 1
fi
prebuild_aarch64 $image_tag $base_name $build_dir/${ROS2_DISTRO}-custom image_tag
if [ $? -ne 0 ]; then
red "failed to build $image_tag"
return 1
fi
}
arch=$(uname -m)
if [ $arch != "x86_64" ] && [ $arch != "aarch64" ]; then
red "Unknown architecture: $arch"
exit 1
fi
eval "prebuild_ros2_${arch}"