Skip to content

Commit

Permalink
generate rosdep package list in the separate step
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Feb 28, 2024
1 parent 664d93b commit 927a568
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
ARG ROS_DISTRO=humble
ARG PREFIX=

## =========================== rosdep output ===============================

FROM ros:humble-ros-core AS rosdep_output

SHELL ["/bin/bash", "-c"]

WORKDIR /ros2_ws
RUN mkdir src

RUN apt-get update && apt-get install -y \
python3-pip \
python3-rosdep \
python3-vcstool \
git

RUN git clone --depth 1 -b master https://github.com/husarion/rosbot_xl_ros.git src && \
vcs import src < src/rosbot_xl/rosbot_xl_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_xl_gazebo && \
rosdep init && \
rosdep update --rosdistro $ROS_DISTRO && \
rosdep install --from-paths src --ignore-src -y --simulate > /rosdep_output.txt && \
echo $(cat /ros2_ws/src/rosbot_xl/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') > /version.txt && \
# for backward compatibility
chmod +x src/rosbot_xl_utils/rosbot_xl_utils/flash-firmware.py && \
cp src/rosbot_xl_utils/rosbot_xl_utils/flash-firmware.py / && \
cp src/rosbot_xl_utils/firmware/firmware-*.bin /firmware.bin

## =========================== Healthcheck builder ===============================

FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS healthcheck_builder
Expand Down Expand Up @@ -42,6 +73,8 @@ SHELL ["/bin/bash", "-c"]
WORKDIR /ros2_ws
RUN mkdir src

COPY --from=rosdep_output /rosdep_output.txt /rosdep_output.txt

RUN apt-get update && apt-get install -y \
python3-pip

Expand All @@ -52,20 +85,10 @@ RUN git clone --depth 1 -b master https://github.com/husarion/rosbot_xl_ros.git
rm -rf src/ros2_controllers && \
# it is necessary to remove simulation - otherwise rosdep tries to install dependencies
rm -r src/rosbot_xl_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 --simulate > /rosdep_output.txt && \
rosdep install --from-paths src --ignore-src -y && \
bash -c "$(cat /rosdep_output.txt)" && \
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_xl/package.xml | grep '<version>' | sed -r 's/.*<version>([0-9]+.[0-9]+.[0-9]+)<\/version>/\1/g') > /version.txt && \
# for backward compatibility
chmod +x src/rosbot_xl_utils/rosbot_xl_utils/flash-firmware.py && \
cp src/rosbot_xl_utils/rosbot_xl_utils/flash-firmware.py / && \
cp install/rosbot_xl_utils/share/rosbot_xl_utils/firmware/firmware-*.bin /firmware.bin && \
# make the /ros2_ws smaller
rm -rf build log src

Expand All @@ -79,15 +102,15 @@ 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=ros_builder /rosdep_output.txt /rosdep_output.txt
COPY --from=rosdep_output /version.txt /version.txt
COPY --from=rosdep_output /flash-firmware.py /flash-firmware.py
COPY --from=rosdep_output /flash-firmware.py /usr/bin/flash-firmware.py
COPY --from=rosdep_output /firmware.bin /firmware.bin
COPY --from=rosdep_output /firmware.bin /root/firmware.bin
COPY --from=rosdep_output /rosdep_output.txt /rosdep_output.txt

# for backward compatibility
COPY --from=ros_builder /flash-firmware.py /flash-firmware.py
COPY --from=ros_builder /flash-firmware.py /usr/bin/flash-firmware.py
COPY --from=ros_builder /firmware.bin /firmware.bin
COPY --from=ros_builder /firmware.bin /root/firmware.bin
COPY --from=ros_builder /ros2_ws /ros2_ws

COPY --from=healthcheck_builder /ros2_ws /ros2_ws_healthcheck

Expand All @@ -96,7 +119,6 @@ RUN apt-get update && apt-get install -y \
stm32flash \
libusb-1.0 \
screen \
ros-$ROS_DISTRO-robot-state-publisher \
ros-$ROS_DISTRO-teleop-twist-keyboard && \
bash -c "$(cat /rosdep_output.txt)" && \
apt-get remove -y \
Expand Down

0 comments on commit 927a568

Please sign in to comment.