File size: 2,670 Bytes
da5a206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Base image that builds all packages
FROM ros:humble-ros-core AS base-builder

# Set environment variables
ENV ROS_DISTRO=humble
ENV DEBIAN_FRONTEND=noninteractive

# Install build dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    git \
    python3-colcon-common-extensions \
    python3-catkin-pkg \
    python3-rosdep \
    ros-${ROS_DISTRO}-rclcpp \
    ros-${ROS_DISTRO}-control-msgs \
    ros-${ROS_DISTRO}-std-msgs \
    ros-${ROS_DISTRO}-sensor-msgs \
    ros-${ROS_DISTRO}-rosbag2-cpp \
    ros-${ROS_DISTRO}-rosidl-runtime-cpp \
    && rm -rf /var/lib/apt/lists/*

# Create workspace
WORKDIR /workspace

# Copy the entire workspace
COPY ros_ws/src/ /workspace/src/

# Build all packages
RUN . /opt/ros/${ROS_DISTRO}/setup.sh && \
    colcon build

# Create base runtime image with sidecar infrastructure
FROM ros:humble-ros-core AS base-runtime

# Set environment variables
ENV ROS_DISTRO=humble
ENV DEBIAN_FRONTEND=noninteractive

# Install runtime dependencies + Python for sidecar
RUN apt-get update && apt-get install -y \
    ros-${ROS_DISTRO}-rclcpp \
    ros-${ROS_DISTRO}-control-msgs \
    ros-${ROS_DISTRO}-std-msgs \
    ros-${ROS_DISTRO}-sensor-msgs \
    ros-${ROS_DISTRO}-rosbag2-cpp \
    ros-${ROS_DISTRO}-rosidl-runtime-cpp \
    ros-${ROS_DISTRO}-rosbag2-storage-default-plugins \
    ros-${ROS_DISTRO}-rmw-fastrtps-cpp \
    ros-${ROS_DISTRO}-rmw-implementation \
    python3 \
    python3-pip \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy the entire install directory from builder stage
COPY --from=base-builder /workspace/install /opt/ros/${ROS_DISTRO}/install

# Install Python dependencies for sidecar infrastructure
COPY orchestration/sidecar/requirements.txt /app/
RUN pip3 install --no-cache-dir -r /app/requirements.txt

# Copy sidecar application (available to all components)
COPY orchestration/sidecar/sidecar_app.py /app/

# Create standard directories
RUN mkdir -p /app/logs /bags

# Set up common entrypoint
COPY ros_ws/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Create non-root user for components
RUN groupadd -r robotics && useradd -r -g robotics robotics

# Create ROS2 logging directory for robotics user
RUN mkdir -p /home/robotics/.ros/log
RUN chown -R robotics:robotics /app /bags /usr/local/bin/entrypoint.sh /home/robotics

# Health check for base infrastructure
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD ros2 --version && python3 -c "import requests; print('Base infrastructure healthy')" || exit 1

# Switch to non-root user
USER robotics

ENTRYPOINT ["entrypoint.sh"]