Skip to content

Commit

Permalink
cleaner dockerfile for building hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Dec 4, 2023
1 parent 4cc21cc commit e36b578
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 203 deletions.
155 changes: 0 additions & 155 deletions Dockerfile

This file was deleted.

103 changes: 55 additions & 48 deletions Dockerfile.hardware
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG PREFIX=
ARG ROSBOT_FW_RELEASE=0.8.0
## ============================ STM32FLASH =================================
# stm32flash needs an older version of glibc (2.28), which is why ubuntu 18.04 was used
FROM ubuntu:18.04 AS stm32flash_builder_and_downloader
FROM ubuntu:18.04 AS stm32flash_builder

ARG ROS_DISTRO
ARG ROSBOT_FW_RELEASE
Expand All @@ -26,8 +26,6 @@ RUN echo ros_distro=$ROS_DISTRO firmware_release=$ROSBOT_FW_RELEASE
RUN curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.bin -o /firmware.bin && \
curl -L https://github.com/husarion/rosbot_ros2_firmware/releases/download/$ROSBOT_FW_RELEASE/firmware.hex -o /firmware.hex

RUN git clone https://github.com/husarion/rosbot_ros.git /ros2_ws/src -b ros2-combined-microros

## =========================== Firmware CPU ID ================================

FROM ubuntu:20.04 AS cpu_id_builder
Expand All @@ -50,51 +48,39 @@ RUN pip3 install -U platformio && \
pio run && \
chmod -x .pio/build/olimex_e407/firmware.bin

## =========================== Micro ROS agent ===============================

FROM husarion/micro-ros-agent:humble-3.1.3-20231122 AS microros_agent_getter

## =========================== ROS image ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-core
## =========================== ROS builder ===============================
FROM husarnet/ros:${PREFIX}${ROS_DISTRO}-ros-base AS ros_builder

ARG ROS_DISTRO
ARG PREFIX

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

RUN mkdir -p /ros2_ws/src && cd /ros2_ws/src
WORKDIR /ros2_ws
RUN mkdir src

# copy firmware built in previous stage and downloaded repository
COPY --from=stm32flash_builder_and_downloader /firmware.bin /root/firmware.bin
COPY --from=stm32flash_builder_and_downloader /firmware.hex /root/firmware.hex
COPY --from=stm32flash_builder_and_downloader /stm32flash/stm32flash /usr/bin/stm32flash
COPY --from=stm32flash_builder_and_downloader /ros2_ws /ros2_ws
COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin
COPY ./healthcheck.cpp /

RUN apt-get update && apt-get install -y \
git \
python3-pip \
python3-colcon-common-extensions \
python3-rosdep \
python3-vcstool \
python3-sh \
python3-periphery \
build-essential \
ros-$ROS_DISTRO-teleop-twist-keyboard && \
python3-periphery && \
pip3 install pyserial && \
MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
git clone https://github.com/husarion/rosbot_ros.git src -b ros2-combined-microros && \
vcs import src < src/rosbot/rosbot_hardware.repos && \
# 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 -i --from-path src --rosdistro $ROS_DISTRO -y && \
# Create health check package
cd src/ && \
rosdep install -i --from-path src --rosdistro $ROS_DISTRO -y

# Create health check package and build
RUN cd src/ && \
MYDISTRO=${PREFIX:-ros}; MYDISTRO=${MYDISTRO//-/} && \
source /opt/$MYDISTRO/$ROS_DISTRO/setup.bash && \
ros2 pkg create healthcheck_pkg --build-type ament_cmake --dependencies rclcpp nav_msgs && \
sed -i '/find_package(nav_msgs REQUIRED)/a \
Expand All @@ -105,40 +91,61 @@ RUN apt-get update && apt-get install -y \
mv /healthcheck.cpp /ros2_ws/src/healthcheck_pkg/src/ && \
cd .. && \
# Build
colcon build && \
# clear ubuntu packages
colcon build --packages-skip \
ackermann_steering_controller \
bicycle_steering_controller \
tricycle_steering_controller \
ros2_controllers \
effort_controllers \
admittance_controller \
force_torque_sensor_broadcaster \
forward_command_controller \
gripper_controllers \
joint_trajectory_controller \
position_controllers \
rqt_joint_trajectory_controller \
tricycle_controller \
velocity_controllers \
ros2_controllers_test_nodes

## =========================== 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

RUN apt-get update && apt-get install -y \
python3-rosdep \
ros-$ROS_DISTRO-teleop-twist-keyboard && \
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 && \
apt-get clean && \
apt-get remove -y \
git \
python3-colcon-common-extensions \
python3-rosdep \
python3-vcstool \
python3-pip \
build-essential && \
rm -rf /var/lib/apt/lists/*

# copy firmware built in previous stage and downloaded repository
COPY --from=stm32flash_builder /firmware.bin /root/firmware.bin
COPY --from=stm32flash_builder /firmware.hex /root/firmware.hex
COPY --from=stm32flash_builder /stm32flash/stm32flash /usr/bin/stm32flash

COPY --from=cpu_id_builder /read_cpu_id/.pio/build/olimex_e407/firmware.bin /firmware_read_cpu_id.bin

RUN 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

COPY ros_entrypoint.sh /
COPY vulcanexus_entrypoint.sh /
COPY healthcheck.sh /

RUN if [[ ${PREFIX} == 'vulcanexus-' ]]; then \
sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \
ros2 run healthcheck_pkg healthcheck_node &' \
/vulcanexus_entrypoint.sh; \
else \
sed -i '/test -f "\/ros2_ws\/install\/setup.bash" && source "\/ros2_ws\/install\/setup.bash"/a \
ros2 run healthcheck_pkg healthcheck_node &' \
/ros_entrypoint.sh; \
fi

COPY ./healthcheck.sh /
HEALTHCHECK --interval=7s --timeout=2s --start-period=5s --retries=5 \
CMD ["/healthcheck.sh"]

# copy micro-ros agent

COPY --from=microros_agent_getter /ros2_ws /ros2_ws_microros_agent
COPY microros_localhost_only.xml /

# copy scripts
Expand Down

0 comments on commit e36b578

Please sign in to comment.