From 8967fcdd86ece2cd1b605ac9b5a63dd7cd187a3d Mon Sep 17 00:00:00 2001 From: dominikn Date: Tue, 15 Nov 2022 13:35:17 +0100 Subject: [PATCH] make the agent image 4x smaller thanks to multi stage build --- base/Dockerfile | 4 ++-- micro-ROS-Agent/Dockerfile | 16 ++++++++++++++-- micro-ROS-Agent/micro-ros_entrypoint.sh | 10 ++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/base/Dockerfile b/base/Dockerfile index b9b4e85..f69854d 100644 --- a/base/Dockerfile +++ b/base/Dockerfile @@ -1,7 +1,7 @@ FROM ros:humble -RUN mkdir -p uros_ws -WORKDIR uros_ws +WORKDIR /uros_ws + RUN git clone --depth 1 -b humble https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup \ && . /opt/ros/$ROS_DISTRO/setup.sh \ && apt update \ diff --git a/micro-ROS-Agent/Dockerfile b/micro-ROS-Agent/Dockerfile index bcd9f15..07316b9 100644 --- a/micro-ROS-Agent/Dockerfile +++ b/micro-ROS-Agent/Dockerfile @@ -1,4 +1,4 @@ -FROM microros/base:humble +FROM microros/base:humble AS micro-ros-agent-builder WORKDIR /uros_ws RUN . /opt/ros/$ROS_DISTRO/setup.sh \ @@ -8,10 +8,22 @@ RUN . /opt/ros/$ROS_DISTRO/setup.sh \ && ros2 run micro_ros_setup build_agent.sh \ && rm -rf log/ build/ src/ +FROM ros:humble-ros-core + +COPY --from=micro-ros-agent-builder /uros_ws /uros_ws + +WORKDIR /uros_ws + # Disable shared memory COPY disable_fastdds_shm.xml disable_fastdds_shm_localhost_only.xml /tmp/ +ENV RMW_IMPLEMENTATION=rmw_fastrtps_cpp +ENV MICROROS_DISABLE_SHM=1 + +RUN echo ". /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc +RUN echo ". /uros_ws/install/setup.bash" >> ~/.bashrc + # setup entrypoint COPY ./micro-ros_entrypoint.sh / ENTRYPOINT ["/bin/sh", "/micro-ros_entrypoint.sh"] -CMD ["--help"] +CMD ["--help"] \ No newline at end of file diff --git a/micro-ROS-Agent/micro-ros_entrypoint.sh b/micro-ROS-Agent/micro-ros_entrypoint.sh index f645b70..6565933 100755 --- a/micro-ROS-Agent/micro-ros_entrypoint.sh +++ b/micro-ROS-Agent/micro-ros_entrypoint.sh @@ -1,10 +1,12 @@ . "/opt/ros/$ROS_DISTRO/setup.sh" . "/uros_ws/install/local_setup.sh" -if [ "$ROS_LOCALHOST_ONLY" = "1" ] ; then - export FASTRTPS_DEFAULT_PROFILES_FILE=/tmp/disable_fastdds_shm_localhost_only.xml -else - export FASTRTPS_DEFAULT_PROFILES_FILE=/tmp/disable_fastdds_shm.xml +if [ "$MICROROS_DISABLE_SHM" = "1" ] ; then + if [ "$ROS_LOCALHOST_ONLY" = "1" ] ; then + export FASTRTPS_DEFAULT_PROFILES_FILE=/tmp/disable_fastdds_shm_localhost_only.xml + else + export FASTRTPS_DEFAULT_PROFILES_FILE=/tmp/disable_fastdds_shm.xml + fi fi exec ros2 run micro_ros_agent micro_ros_agent "$@"