-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·243 lines (219 loc) · 7.59 KB
/
build.sh
File metadata and controls
executable file
·243 lines (219 loc) · 7.59 KB
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
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
WORKSPACE_ROOT="$SCRIPT_DIR"
# Function to print help message
print_help() {
echo "Usage: build.sh [OPTIONS]"
echo "Options:"
echo " -h | --help Display this help message"
echo " --platform Specify the platform (linux/amd64 or linux/arm64, default: current platform)"
echo " --ros-distro Specify ROS distribution (humble or jazzy, default: humble)"
echo " --no-cuda Do not build CUDA images (default: false)"
echo " --target Specify the target images to build (common, components, universe, default: components)"
}
# Parse arguments
parse_arguments() {
while [ "$1" != "" ]; do
case "$1" in
--help | -h)
print_help
exit 1
;;
--no-cuda)
option_no_cuda=true
;;
--platform)
option_platform="$2"
shift
;;
--target)
option_target="$2"
shift
;;
--ros-distro)
option_ros_distro="$2"
shift
;;
*)
echo "Unknown option: $1"
print_help
exit 1
;;
esac
shift
done
}
# Set ROS distribution
set_ros_distro() {
if [ -n "$option_ros_distro" ]; then
ros_distro="$option_ros_distro"
else
ros_distro="humble"
fi
}
# Set build options
set_build_options() {
if [ -n "$option_target" ]; then
target="$option_target"
else
target="components"
fi
}
# Set platform
set_platform() {
if [ -n "$option_platform" ]; then
platform="$option_platform"
else
platform="linux/amd64"
if [ "$(uname -m)" = "aarch64" ]; then
platform="linux/arm64"
fi
fi
}
# Clone autoware repositories
clone_repositories() {
cd "$WORKSPACE_ROOT"
if [ ! -d "autoware" ]; then
echo "Cloning Autoware repository..."
git clone https://github.com/autowarefoundation/autoware.git autoware
fi
if [ ! -d "autoware/src" ]; then
mkdir -p autoware/src
vcs import autoware/src <autoware/repositories/autoware.repos
else
echo "Source directory already exists. Updating repositories..."
vcs import autoware/src <autoware/repositories/autoware.repos
vcs pull autoware/src
fi
}
# Build images
build_images() {
# https://github.com/docker/buildx/issues/484
export BUILDKIT_STEP_LOG_MAX_SIZE=10000000
local bake_file="$SCRIPT_DIR/components/docker-bake.hcl"
local ubuntu_version="jammy"
if [ "$ros_distro" = "jazzy" ]; then
ubuntu_version="noble"
fi
local base_image="ros:${ros_distro}-ros-base-${ubuntu_version}"
local image_common="openadkit-common"
local image_component="openadkit"
echo "Building images with:"
echo " Target: $target"
echo " Platform: $platform"
echo " ROS distro: $ros_distro"
echo " Base image: $base_image"
echo " CUDA: $([ "$option_no_cuda" = "true" ] && echo "disabled" || echo "enabled")"
set -x
# =========================================================================
# Stage 1: Common images
# =========================================================================
docker buildx bake --allow=ssh --load --progress=plain -f "$bake_file" \
--set "*.context=$WORKSPACE_ROOT" \
--set "*.ssh=default" \
--set "*.platform=$platform" \
--set "*.args.ROS_DISTRO=$ros_distro" \
--set "*.args.BASE_IMAGE=$base_image" \
--set "common-base.tags=${image_common}:base" \
--set "common-devel.tags=${image_common}:devel" \
common-base common-devel
if [ "$option_no_cuda" != "true" ]; then
docker buildx bake --allow=ssh --load --progress=plain -f "$bake_file" \
--set "*.context=$WORKSPACE_ROOT" \
--set "*.ssh=default" \
--set "*.platform=$platform" \
--set "*.args.ROS_DISTRO=$ros_distro" \
--set "*.args.BASE_IMAGE=$base_image" \
--set "common-base-cuda.tags=${image_common}:base-cuda" \
--set "common-devel-cuda.tags=${image_common}:devel-cuda" \
common-base-cuda common-devel-cuda
fi
if [ "$target" = "common" ]; then
set +x
return
fi
# =========================================================================
# Stage 2: Component images
# =========================================================================
docker buildx bake --allow=ssh --load --progress=plain -f "$bake_file" \
--set "*.context=$WORKSPACE_ROOT" \
--set "*.ssh=default" \
--set "*.platform=$platform" \
--set "*.args.ROS_DISTRO=$ros_distro" \
--set "*.args.COMMON_BASE_IMAGE=${image_common}:base" \
--set "*.args.COMMON_DEVEL_IMAGE=${image_common}:devel" \
--set "sensing-perception.tags=${image_component}:sensing-perception" \
--set "localization-mapping.tags=${image_component}:localization-mapping" \
--set "planning-control.tags=${image_component}:planning-control" \
--set "vehicle-system.tags=${image_component}:vehicle-system" \
--set "api.tags=${image_component}:api" \
--set "visualizer.tags=${image_component}:visualizer" \
--set "simulator.tags=${image_component}:simulator" \
sensing-perception localization-mapping planning-control vehicle-system api visualizer simulator
if [ "$option_no_cuda" != "true" ]; then
docker buildx bake --allow=ssh --load --progress=plain -f "$bake_file" \
--set "*.context=$WORKSPACE_ROOT" \
--set "*.ssh=default" \
--set "*.platform=$platform" \
--set "*.args.ROS_DISTRO=$ros_distro" \
--set "*.args.COMMON_BASE_CUDA_IMAGE=${image_common}:base-cuda" \
--set "*.args.COMMON_DEVEL_CUDA_IMAGE=${image_common}:devel-cuda" \
--set "sensing-perception-cuda.tags=${image_component}:sensing-perception-cuda" \
sensing-perception-cuda
fi
if [ "$target" = "components" ]; then
set +x
return
fi
# =========================================================================
# Stage 3: Universe images
# =========================================================================
docker buildx bake --allow=ssh --load --progress=plain -f "$bake_file" \
--set "*.context=$WORKSPACE_ROOT" \
--set "*.ssh=default" \
--set "*.platform=$platform" \
--set "*.args.ROS_DISTRO=$ros_distro" \
--set "*.args.COMMON_BASE_IMAGE=${image_common}:base" \
--set "*.args.COMMON_DEVEL_IMAGE=${image_common}:devel" \
--set "*.args.SENSING_PERCEPTION_IMAGE=${image_component}:sensing-perception" \
--set "*.args.LOCALIZATION_MAPPING_IMAGE=${image_component}:localization-mapping" \
--set "*.args.PLANNING_CONTROL_IMAGE=${image_component}:planning-control" \
--set "*.args.VEHICLE_SYSTEM_IMAGE=${image_component}:vehicle-system" \
--set "*.args.API_IMAGE=${image_component}:api" \
--set "*.args.VISUALIZER_IMAGE=${image_component}:visualizer" \
--set "*.args.SIMULATOR_IMAGE=${image_component}:simulator" \
--set "universe.tags=${image_component}:universe" \
universe
if [ "$option_no_cuda" != "true" ]; then
docker buildx bake --allow=ssh --load --progress=plain -f "$bake_file" \
--set "*.context=$WORKSPACE_ROOT" \
--set "*.ssh=default" \
--set "*.platform=$platform" \
--set "*.args.ROS_DISTRO=$ros_distro" \
--set "*.args.COMMON_BASE_CUDA_IMAGE=${image_common}:base-cuda" \
--set "*.args.COMMON_DEVEL_CUDA_IMAGE=${image_common}:devel-cuda" \
--set "*.args.SENSING_PERCEPTION_CUDA_IMAGE=${image_component}:sensing-perception-cuda" \
--set "*.args.LOCALIZATION_MAPPING_IMAGE=${image_component}:localization-mapping" \
--set "*.args.PLANNING_CONTROL_IMAGE=${image_component}:planning-control" \
--set "*.args.VEHICLE_SYSTEM_IMAGE=${image_component}:vehicle-system" \
--set "*.args.API_IMAGE=${image_component}:api" \
--set "*.args.VISUALIZER_IMAGE=${image_component}:visualizer" \
--set "*.args.SIMULATOR_IMAGE=${image_component}:simulator" \
--set "universe-cuda.tags=${image_component}:universe-cuda" \
universe-cuda
fi
set +x
}
# Remove dangling images
remove_dangling_images() {
docker image prune -f
}
# Main script execution
parse_arguments "$@"
set_ros_distro
set_build_options
set_platform
clone_repositories
build_images
remove_dangling_images