Skip to content

Commit

Permalink
refactor: dockerfile use multi-stage builds to only include necessary…
Browse files Browse the repository at this point in the history
… files
  • Loading branch information
kluge7 committed Sep 27, 2024
1 parent 9996a7d commit 9e90964
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Base image: using ROS 2 Humble
FROM ros:humble
# Stage 1: Build the ROS 2 workspace
FROM ros:humble AS builder

# Install necessary dependencies
# Install necessary dependencies for building
RUN apt-get update && apt-get install -y \
python3-colcon-common-extensions \
git \
Expand All @@ -16,12 +16,20 @@ COPY . src/vortex-auv
# Clone vortex-msgs repo into the src folder
RUN git clone https://github.com/vortexntnu/vortex-msgs.git src/vortex-msgs

# Source the ROS 2 environment
# Source the ROS 2 environment and build the workspace using colcon
SHELL ["/bin/bash", "-c"]

# Build the workspace using colcon
RUN source /opt/ros/humble/setup.bash && \
colcon build --symlink-install

# Stage 2: Minimal runtime image with the install directory only
FROM ros:humble

# Set up the workspace
WORKDIR /ros2_ws

# Copy only the necessary files from the install directory
COPY --from=builder /ros2_ws/install /ros2_ws/install
COPY --from=builder /ros2_ws/build /ros2_ws/build

# Source the workspace on container start
CMD ["bash", "-c", "source /opt/ros/humble/setup.bash && source install/setup.bash && bash"]
CMD ["bash", "-c", "source /opt/ros/humble/setup.bash && source install/setup.bash && bash"]

0 comments on commit 9e90964

Please sign in to comment.