-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
370 lines (339 loc) · 14 KB
/
Dockerfile
File metadata and controls
370 lines (339 loc) · 14 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
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
# ROS 2 Jazzy Alpine Linux - Multi-stage Build
#
# Builds ROS 2 Jazzy from source on Alpine Linux (musl libc).
# Final image is ~200MB vs ~2GB for Ubuntu-based ROS 2 images.
ARG ALPINE_VERSION=3.21
ARG ROS_DISTRO=jazzy
ARG PARALLEL_JOBS=2
# ===========================================================================
# Builder stage
# ===========================================================================
FROM alpine:${ALPINE_VERSION} AS builder
ARG PARALLEL_JOBS
ARG ROS_DISTRO
RUN apk add --no-cache \
bash \
build-base \
cmake \
ninja \
python3-dev \
py3-pip \
git \
curl \
linux-headers \
eigen-dev \
tinyxml2-dev \
yaml-cpp-dev \
yaml-dev \
pkgconfig \
uncrustify \
cppcheck \
py3-flake8 \
libxml2-utils \
asio-dev \
openssl-dev \
lttng-ust-dev \
swig \
cython \
py3-wheel \
py3-pybind11-dev \
libc-dev
ENV PYTHONWARNINGS=ignore::UserWarning:setuptools._distutils.dist
RUN pip3 install --no-cache-dir --break-system-packages --quiet \
colcon-common-extensions \
lark \
empy \
pyyaml \
numpy \
setuptools \
wheel \
pybind11 \
cython \
cpplint \
pycodestyle \
pydocstyle \
catkin-pkg \
distlib \
vcstool
# Clone ROS 2 source packages pinned to the jazzy branch.
# Shallow clones (--depth 1) speed up the clone step significantly.
# eProsima repos pinned to compatible 2.x versions for Jazzy.
WORKDIR /ros2_ws/src
RUN \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ament/ament_package.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ament/ament_cmake.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ament/ament_index.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ament/googletest.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ament/ament_lint.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/ament_cmake_ros.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rcutils.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rcpputils.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rmw.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rcl.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rclcpp.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rclpy.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/ros2cli.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/geometry2.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/message_filters.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/common_interfaces.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/libyaml_vendor.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/python_cmake_module.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl_python.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rpyutils.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl_core.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl_defaults.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl_dynamic_typesupport.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl_dynamic_typesupport_fastrtps.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl_typesupport.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/unique_identifier_msgs.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rcl_interfaces.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rcl_logging.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rmw_implementation.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rmw_fastrtps.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rmw_dds_common.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/ros2_tracing.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/spdlog_vendor.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/pybind11_vendor.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/rosidl_typesupport_fastrtps.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros-tooling/libstatistics_collector.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/console_bridge_vendor.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros/class_loader.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/orocos_kdl_vendor.git && \
git clone --depth 1 --branch ${ROS_DISTRO} https://github.com/ros2/eigen3_cmake_module.git && \
git clone --depth 1 --branch v2.14.6 https://github.com/eProsima/Fast-DDS.git && \
git clone --depth 1 --branch v2.2.6 https://github.com/eProsima/Fast-CDR.git && \
git clone --depth 1 --branch v1.4.1 https://github.com/eProsima/foonathan_memory_vendor.git
# Remove test/example/benchmark directories to reduce build scope
RUN find . -name "*_test" -type d \
! -path "./ament_cmake/ament_cmake_test*" \
! -path "./ament_cmake/ament_cmake_gmock*" \
! -path "./ament_cmake_ros/rmw_test_fixture*" \
-exec rm -rf {} + 2>/dev/null; \
find . -name "*_tests" -type d -exec rm -rf {} + 2>/dev/null; \
find . -name "test_*" -type d -exec rm -rf {} + 2>/dev/null; \
find . -name "*example*" -type d -exec rm -rf {} + 2>/dev/null; \
find . -name "*demo*" -type d -exec rm -rf {} + 2>/dev/null; \
find . -name "*benchmark*" -type d -exec rm -rf {} + 2>/dev/null; \
true
WORKDIR /ros2_ws
ENV MAKEFLAGS="-j${PARALLEL_JOBS}"
ENV CFLAGS="-Wno-int-conversion -Wno-incompatible-pointer-types -Wno-error"
ENV CXXFLAGS="-Wno-error -Wno-deprecated-declarations -Wno-stringop-overread"
# NOTE: All build stages use identical cmake-args to prevent colcon from
# reconfiguring/rebuilding packages in later stages (which causes setuptools
# race conditions with parallel egg-info installs).
# Build Stage 1: Foundation packages
RUN colcon build \
--packages-select \
gtest_vendor \
gmock_vendor \
ament_package \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+
# Build Stage 2: Ament build system
# Sequential executor prevents setuptools egg-info race conditions
# between parallel Python package installs sharing site-packages.
RUN bash -c 'source install/setup.bash && \
colcon build \
--executor sequential \
--packages-up-to \
ament_cmake \
ament_lint_common \
ament_mypy \
ament_index_python \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
# Build Stage 3: External dependencies
RUN bash -c 'source install/setup.bash && \
colcon build \
--packages-up-to \
foonathan_memory_vendor \
fastcdr \
libyaml_vendor \
spdlog_vendor \
pybind11_vendor \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
# Build Stage 4: Fast-DDS middleware (heavy, separate layer for caching)
RUN bash -c 'source install/setup.bash && \
colcon build \
--packages-up-to \
fastrtps \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DBUILD_DOCUMENTATION=OFF \
-DCOMPILE_EXAMPLES=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
# Build Stage 5: rpyutils
RUN bash -c 'source install/setup.bash && \
colcon build \
--packages-select \
rpyutils \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
# Build Stage 6: ROSIDL core
RUN bash -c 'source install/setup.bash && \
colcon build \
--packages-up-to \
python_cmake_module \
rosidl_generator_py \
rosidl_adapter \
rosidl_cmake \
rosidl_parser \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
# Build Stage 7: RMW implementations
RUN bash -c 'source install/setup.bash && \
colcon build \
--packages-up-to \
rmw_fastrtps_cpp \
rmw_fastrtps_shared_cpp \
rmw_fastrtps_dynamic_cpp \
rosidl_typesupport_fastrtps_cpp \
rosidl_typesupport_fastrtps_c \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
# Build Stage 8: Core ROS packages (rclcpp, rclpy, CLI)
RUN bash -c 'source install/setup.bash && \
colcon build \
--packages-up-to \
rclcpp \
rclcpp_action \
rclcpp_components \
rclcpp_lifecycle \
rclpy \
ros2cli \
--packages-skip \
libyaml_vendor \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
# Build Stage 9: Message interfaces and transforms
RUN bash -c 'source install/setup.bash && \
colcon build \
--packages-up-to \
std_msgs \
geometry_msgs \
sensor_msgs \
nav_msgs \
diagnostic_msgs \
visualization_msgs \
shape_msgs \
trajectory_msgs \
stereo_msgs \
unique_identifier_msgs \
action_msgs \
tf2 \
tf2_ros \
tf2_geometry_msgs \
tf2_msgs \
message_filters \
--packages-skip \
libyaml_vendor \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DPYTHON_EXECUTABLE=/usr/bin/python3 \
-DPython3_EXECUTABLE=/usr/bin/python3 \
-DCMAKE_C_FLAGS="${CFLAGS}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
--event-handlers console_direct+'
ENV RMW_IMPLEMENTATION=rmw_fastrtps_cpp
# ===========================================================================
# Runtime stage - Clean Alpine with only runtime dependencies
# ===========================================================================
FROM alpine:${ALPINE_VERSION} AS runtime
ARG ROS_DISTRO
LABEL org.opencontainers.image.title="ROS 2 Jazzy on Alpine Linux"
LABEL org.opencontainers.image.description="Minimal ROS 2 Jazzy built from source on Alpine Linux"
LABEL org.opencontainers.image.source="https://github.com/PavelGuzenfeld/ros2-alpine"
LABEL org.opencontainers.image.licenses="MIT"
LABEL ros.distro="${ROS_DISTRO}"
RUN apk add --no-cache \
python3 \
py3-setuptools \
py3-yaml \
py3-numpy \
py3-pip \
py3-wheel \
bash \
libstdc++ \
libgcc \
tinyxml2 \
yaml-cpp \
yaml \
openssl \
lttng-ust \
eigen-dev
ENV PYTHONWARNINGS=ignore::UserWarning:setuptools._distutils.dist
RUN pip3 install --no-cache-dir --break-system-packages --quiet \
lark \
wheel \
colcon-common-extensions \
typing_extensions
RUN mkdir -p /opt/ros/jazzy
COPY --from=builder /ros2_ws/install /opt/ros/jazzy
ENV ROS_VERSION=2 \
ROS_DISTRO=jazzy \
ROS_PYTHON_VERSION=3 \
RMW_IMPLEMENTATION=rmw_fastrtps_cpp
RUN if [ -f /opt/ros/jazzy/setup.bash ]; then \
chmod +x /opt/ros/jazzy/setup.bash; \
else \
printf '#!/bin/bash\n. /opt/ros/jazzy/local_setup.bash\n' > /opt/ros/jazzy/setup.bash; \
chmod +x /opt/ros/jazzy/setup.bash; \
fi
RUN adduser -D -h /home/ros ros && \
mkdir -p /workspace/src && \
chown -R ros:ros /workspace
USER ros
WORKDIR /workspace
SHELL ["/bin/bash", "-c"]
CMD ["bash", "-c", "source /opt/ros/jazzy/setup.bash && echo 'ROS 2 Jazzy Alpine ready!' && exec bash"]