FROM osrf/ros:jazzy-desktop-full

ENV DEBIAN_FRONTEND=noninteractive
ENV ROS_DISTRO=jazzy

# Install Gazebo Harmonic (paired with ROS 2 Jazzy), Kobuki dependencies, colcon, and Mesa/GUI utilities
RUN apt-get update && apt-get install -y --no-install-recommends \
    ros-${ROS_DISTRO}-ros-gz \
    ros-${ROS_DISTRO}-kobuki-ros-interfaces \
    ros-${ROS_DISTRO}-kobuki-velocity-smoother \
    ros-${ROS_DISTRO}-sophus \
    ros-${ROS_DISTRO}-ecl-build \
    ros-${ROS_DISTRO}-teleop-twist-keyboard \
    ros-${ROS_DISTRO}-teleop-twist-joy \
    ros-${ROS_DISTRO}-joy-teleop \
    ros-${ROS_DISTRO}-xacro \
    ros-${ROS_DISTRO}-robot-state-publisher \
    ros-${ROS_DISTRO}-joint-state-publisher \
    ros-${ROS_DISTRO}-joint-state-publisher-gui \
    ros-${ROS_DISTRO}-laser-filters \
    ros-${ROS_DISTRO}-ros-testing \
    ros-${ROS_DISTRO}-gz-ros2-control \
    ros-${ROS_DISTRO}-ros2-control \
    ros-${ROS_DISTRO}-ros2-controllers \
    ros-${ROS_DISTRO}-moveit \
    ros-${ROS_DISTRO}-behaviortree-cpp \
    ros-${ROS_DISTRO}-generate-parameter-library \
    ros-${ROS_DISTRO}-realtime-tools \
    ros-${ROS_DISTRO}-robot-localization \
    ros-${ROS_DISTRO}-imu-filter-madgwick \
    ros-${ROS_DISTRO}-nmea-navsat-driver \
    ros-${ROS_DISTRO}-phidgets-api \
    ros-${ROS_DISTRO}-joy-linux \
    ros-${ROS_DISTRO}-nav2-common \
    ros-${ROS_DISTRO}-husarion-mecanum-drive-controller \
    ros-${ROS_DISTRO}-twist-mux-controller \
    ros-${ROS_DISTRO}-depthai-descriptions \
    ros-${ROS_DISTRO}-kortex-description \
    ros-${ROS_DISTRO}-realsense2-description \
    ros-${ROS_DISTRO}-robotiq-description \
    ros-${ROS_DISTRO}-ur-description \
    ros-${ROS_DISTRO}-zed-description \
    qtdeclarative5-dev \
    qml-module-qtquick2 \
    qml-module-qtquick-controls2 \
    qml-module-qtquick-layouts \
    qml-module-qtquick-window2 \
    python3-click \
    python3-transforms3d \
    autoconf-archive \
    libtool \
    libtool-bin \
    iputils-ping \
    iproute2 \
    libusb-1.0-0-dev \
    libftdi1-dev \
    python3-colcon-common-extensions \
    python3-rosdep \
    python3-vcstool \
    git \
    nano \
    curl \
    wget \
    mesa-utils \
    libgl1-mesa-dri \
    libglx-mesa0 \
    x11-apps \
    && rm -rf /var/lib/apt/lists/*

# Create workspace directory
WORKDIR /ros2_ws
RUN mkdir -p /ros2_ws/src

# Automatically source ROS 2 and workspace in interactive bash sessions
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /root/.bashrc && \
    echo "if [ -f /ros2_ws/install/setup.bash ]; then source /ros2_ws/install/setup.bash; fi" >> /root/.bashrc

COPY entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r$//' /entrypoint.sh && chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
