Refactor Dockerfile and update dependencies for improved build efficiency and runtime support

This commit is contained in:
Akash Shingha 2026-03-11 18:43:51 +02:00
parent 4cc9d151ed
commit 8c37334b20
3 changed files with 6 additions and 17 deletions

View File

@ -2,22 +2,21 @@ FROM ros:humble-ros-base AS build
SHELL ["/bin/bash", "-lc"] SHELL ["/bin/bash", "-lc"]
WORKDIR /ws WORKDIR /ws
# Install OS packages first (cached layer when requirements.txt unchanged) # Install build dependencies
COPY apt-requirements.txt /tmp/requirements.txt COPY apt-requirements.txt /tmp/requirements.txt
RUN apt-get update \ RUN apt-get update \
&& xargs -a /tmp/requirements.txt apt-get install -y --no-install-recommends \ && xargs -a /tmp/requirements.txt apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* /tmp/requirements.txt && rm -rf /var/lib/apt/lists/* /tmp/requirements.txt
# Copy package manifest(s) so rosdep can install system deps and this layer caches # Copy package manifest and install rosdeps
COPY package.xml ./package.xml COPY package.xml ./package.xml
RUN add-apt-repository multiverse || true
RUN source /opt/ros/humble/setup.bash \ RUN source /opt/ros/humble/setup.bash \
&& rosdep update || true \ && rosdep update || true \
&& rosdep install -i --from-paths . --rosdistro humble -y || true && rosdep install -i --from-paths . --rosdistro humble -y || true
# Copy rest of the sources after deps to avoid busting the deps layer on code changes # Copy sources and build
COPY . . COPY . .
# Build with Ninja + ccache for faster incremental builds inside the container
RUN source /opt/ros/humble/setup.bash \ RUN source /opt/ros/humble/setup.bash \
&& CCACHE_DIR=/ccache mkdir -p /ccache \ && CCACHE_DIR=/ccache mkdir -p /ccache \
&& chmod 777 /ccache \ && chmod 777 /ccache \
@ -39,7 +38,6 @@ RUN chmod +x /ros_entrypoint.sh
ENV ROS_DISTRO=humble ENV ROS_DISTRO=humble
## Make ROS and workspace overlays available for interactive shells ## Make ROS and workspace overlays available for interactive shells
# This ensures `docker exec -it <container> bash` has `ros2` on PATH
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash || true" > /etc/profile.d/ros2.sh \ RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash || true" > /etc/profile.d/ros2.sh \
&& echo "[ -f /ws/install/setup.bash ] && source /ws/install/setup.bash" >> /etc/profile.d/ros2.sh \ && echo "[ -f /ws/install/setup.bash ] && source /ws/install/setup.bash" >> /etc/profile.d/ros2.sh \
&& chmod +x /etc/profile.d/ros2.sh && chmod +x /etc/profile.d/ros2.sh

View File

@ -1,18 +1,15 @@
python3-colcon-common-extensions python3-colcon-common-extensions
python3-pip
git
build-essential build-essential
cmake cmake
pkg-config pkg-config
libopencv-dev libopencv-dev
python3-opencv python3-opencv
curl
python3-rosdep python3-rosdep
python3-rosdistro python3-rosdistro
software-properties-common
libgstreamer1.0-dev libgstreamer1.0-dev
libgstreamer-plugins-base1.0-dev libgstreamer-plugins-base1.0-dev
libgstreamer-plugins-good1.0-dev libgstreamer-plugins-good1.0-dev
libgstreamer-plugins-bad1.0-dev
libgstrtspserver-1.0-dev libgstrtspserver-1.0-dev
ccache
ninja-build ninja-build
ccache

View File

@ -1,13 +1,7 @@
libgstreamer1.0-0 libgstreamer1.0-0
gstreamer1.0-plugins-base gstreamer1.0-plugins-base
gstreamer1.0-plugins-good gstreamer1.0-plugins-good
gstreamer1.0-plugins-bad
gstreamer1.0-plugins-ugly gstreamer1.0-plugins-ugly
libgstrtspserver-1.0-0 libgstrtspserver-1.0-0
python3-opencv python3-opencv
libopencv-dev
ros-humble-ros2cli ros-humble-ros2cli
ros-humble-rclpy
net-tools
iputils-ping