-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile.hardware
117 lines (90 loc) · 3.99 KB
/
Dockerfile.hardware
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
ARG ROS_DISTRO=humble
ARG PREFIX=
## =========================== Healthcheck builder ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS healthcheck_builder
ARG ROS_DISTRO
ARG PREFIX
SHELL ["/bin/bash", "-c"]
WORKDIR /ros2_ws
RUN mkdir src && \
cd src && \
MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
# Create health check package
ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \
sed -i '/find_package(nav_msgs REQUIRED)/a \
add_executable(healthcheck_node src/healthcheck.cpp)\n \
ament_target_dependencies(healthcheck_node rclcpp nav_msgs)\n \
install(TARGETS healthcheck_node DESTINATION lib/${PROJECT_NAME})' \
/ros2_ws/src/healthcheck_pkg/CMakeLists.txt
COPY healthcheck.cpp src/healthcheck_pkg/src/
RUN MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
rm -rf build log src
## =========================== ROS builder ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder
ARG ROS_DISTRO
ARG PREFIX
SHELL ["/bin/bash", "-c"]
WORKDIR /ros2_ws
RUN mkdir src
COPY ./healthcheck.cpp /
RUN apt-get update && apt-get install -y \
python3-pip
RUN git clone --depth 1 -b humble https://github.com/husarion/rosbot_ros.git src && \
vcs import src < src/rosbot/rosbot_hardware.repos && \
cp -r src/ros2_controllers/diff_drive_controller src/ && \
cp -r src/ros2_controllers/imu_sensor_broadcaster src/ && \
rm -rf src/ros2_controllers && \
# it is necessary to remove simulation - otherwise rosdep tries to install dependencies
rm -r src/rosbot_gazebo && \
# without this line (using vulcanexus base image) rosdep init throws error: "ERROR: default sources list file already exists:"
rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src --ignore-src -y && \
MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release && \
echo $(cat /ros2_ws/src/rosbot/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') >> /version.txt && \
rm -rf build log
## =========================== Final Stage ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core
ARG ROS_DISTRO
ARG PREFIX
SHELL ["/bin/bash", "-c"]
WORKDIR /ros2_ws
COPY --from=ros_builder /ros2_ws /ros2_ws
COPY --from=ros_builder /version.txt /version.txt
COPY --from=healthcheck_builder /ros2_ws /ros2_ws_healthcheck
# for backward compatibility
RUN cp src/rosbot_utils/rosbot_utils/flash-firmware.py /usr/bin/ && \
cp src/rosbot_utils/rosbot_utils/flash-firmware.py / && \
cp install/rosbot_utils/share/rosbot_utils/firmware/firmware-*.bin /root/firmware.bin
RUN apt-get update && apt-get install -y \
python3-pip \
python3-rosdep \
stm32flash \
gosu \
ros-$ROS_DISTRO-teleop-twist-keyboard && \
pip3 install pyftdi && \
rm -rf /etc/ros/rosdep/sources.list.d/20-default.list && \
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y && \
# Size optimalization
apt-get remove -y \
python3-rosdep \
python3-pip && \
apt-get clean && \
rm -rf src && \
rm -rf /var/lib/apt/lists/*
COPY healthcheck.sh /
COPY run_healthcheck_node.sh /
COPY print-serial-number.py /usr/bin/
ENV ROBOT_NAMESPACE=
HEALTHCHECK --interval=2s --timeout=1s --start-period=30s --retries=1 \
CMD ["/healthcheck.sh"]
RUN sed -i "/# <additional-user-commands>/r /run_healthcheck_node.sh" /*_entrypoint.sh && \
sed -i "/# <additional-user-commands>/d" /*_entrypoint.sh