From e250038601daba0d9cbd8877a95bb0a4c9a4225f Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Fri, 19 Jan 2024 19:39:32 -0700 Subject: [PATCH] Add multistage, fix cache, add rviz dep * This complets the requests for the PR * Bind mounts on the build reduce cache busting * Add default bash shell * Added parameters for the build type and ROS distro to use Signed-off-by: Ryan Friedman --- Dockerfile | 35 +++++++++++++++++++---------------- Makefile | 4 ---- package.xml | 4 +++- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6f8f472..cf74634 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,31 @@ # Use the official ROS 2 humble base image -FROM ros:humble +ARG ROS_DISTRO=humble +FROM ros:${ROS_DISTRO} as deps # Set the working directory -WORKDIR /root/ros2_ws/src +WORKDIR /root/ros2_ws -COPY . . -# Install additional dependencies -RUN apt-get update \ - && apt-get -y --quiet --no-install-recommends install \ - ros-humble-rviz2 +SHELL ["/bin/bash", "-c"] -# Set environment variables -ENV ROS_VERSION 2 -WORKDIR /root/ros2_ws -RUN . /opt/ros/humble/setup.sh -RUN rosdep update -RUN rosdep install --from-paths src --ignore-src -y +RUN source /opt/ros/${ROS_DISTRO}/setup.bash +RUN --mount=type=bind,source=package.xml,target=src/grid_map_geo/package.xml \ + apt update && \ + rosdep update && \ + rosdep install --from-paths src --ignore-src -y + +# Run a default command, e.g., starting a bash shell +CMD ["bash"] -RUN . /opt/ros/humble/setup.sh && colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-up-to grid_map_geo +FROM deps as builder +ARG CMAKE_BUILD_TYPE=Release + +RUN source /opt/ros/${ROS_DISTRO}/setup.bash +COPY . . +RUN source /opt/ros/${ROS_DISTRO}/setup.bash && \ + colcon build --cmake-args -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} --packages-up-to grid_map_geo # Source the ROS2 setup file RUN echo "source /root/ros2_ws/install/setup.bash" >> ~/.bashrc -# Expose the default ROS 2 communication ports -EXPOSE 11311 # Run a default command, e.g., starting a bash shell CMD ["bash"] diff --git a/Makefile b/Makefile index 50865b8..0491396 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,3 @@ docker_build: .PHONY : docker_run docker_run: docker run -it --net=host --ipc=host --privileged --env="DISPLAY" --env="QT_X11_NO_MITSHM=1" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" --volume="${XAUTHORITY}:/root/.Xauthority" --entrypoint /bin/bash gmg - - - - diff --git a/package.xml b/package.xml index ac5463e..9524e52 100644 --- a/package.xml +++ b/package.xml @@ -19,8 +19,10 @@ libgdal-dev rclcpp yaml_cpp_vendor - ros2launch + grid_map_rviz_plugin + ros2launch + rviz2 ament_cmake