Skip to content

Commit 6d861eb

Browse files
committed
Optimizing Dockerfile
1 parent b03f3f8 commit 6d861eb

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

Dockerfile

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
ARG ROS_DISTRO=humble
2-
FROM ros:${ROS_DISTRO} AS deps
2+
FROM ros:${ROS_DISTRO}-ros-core AS deps
3+
4+
# Install system dependencies early for better caching
5+
RUN apt update && apt install -y --no-install-recommends \
6+
git \
7+
build-essential \
8+
python3-pip \
9+
python3-rosdep \
10+
python3-colcon-common-extensions \
11+
&& rm -rf /var/lib/apt/lists/*
312

413
# Create ros2_ws and copy files
514
WORKDIR /root/ros2_ws
6-
SHELL ["/bin/bash", "-c"]
715
COPY . /root/ros2_ws/src
816

9-
# Install dependencies
10-
RUN apt-get update
11-
RUN apt-get -y --quiet --no-install-recommends install python3 python3-pip
12-
RUN rosdep install --from-paths src --ignore-src -r -y
17+
# Install ROS dependencies
18+
RUN rosdep init && rosdep update --include-eol-distros
19+
RUN apt update && rosdep install --from-paths src --ignore-src -r -y && rm -rf /var/lib/apt/lists/*
1320

14-
RUN if [ "$(lsb_release -rs)" = "24.04" ] || [ "$(lsb_release -rs)" = "24.10" ]; then \
15-
pip3 install -r src/requirements.txt --break-system-packages --ignore-installed; \
21+
# Install Python packages
22+
RUN if [ "$(lsb_release -rs | cut -d. -f1)" -ge 24 ]; then \
23+
pip3 install -r src/requirements.txt --break-system-packages --ignore-installed --no-cache-dir; \
1624
else \
17-
pip3 install -r src/requirements.txt; \
25+
pip3 install -r src/requirements.txt --no-cache-dir; \
1826
fi
1927

20-
# Build the ws with colcon
2128
FROM deps AS builder
22-
ARG CMAKE_BUILD_TYPE=Release
29+
30+
SHELL ["/bin/bash", "-c"]
31+
32+
# Build the workspace
2333
RUN source /opt/ros/${ROS_DISTRO}/setup.bash && colcon build
2434

2535
# Source the ROS 2 setup file

0 commit comments

Comments
 (0)