FROM ros:iron-ros-core
RUN apt-get update && \
    apt-get install -yq git ros-dev-tools python3-colcon-mixin python3-colcon-clean \
    && rosdep init && rosdep update


RUN . /opt/ros/iron/setup.sh && \
    mkdir -p /opt/ros/franka/src && \
    cd /opt/ros/franka/src && \
    git clone https://github.com/m-elwin/franka_ros2 -b iron_patches && \
    git clone --recursive https://github.com/m-elwin/libfranka.git -b numsr  && \
    cd libfranka && \
    git checkout f3b8d775a9c847cab32684c8a316f67867761674  && \
    git submodule update && \
    cd .. && \
    git clone https://github.com/m-elwin/numsr_patches.git -b iron_patches

RUN . /opt/ros/iron/setup.sh && \
    cd /opt/ros/franka && \
    rosdep install --from-paths . --ignore-src -r  -y || : # fails on mongo db but does what we want anyway

RUN . /opt/ros/iron/setup.sh && \
    cd /opt/ros/franka && \
    colcon mixin add numsr_patches file:///opt/ros/franka/src/numsr_patches/index.yaml && \
    colcon mixin update numsr_patches && \
    colcon build --mixin numsr

RUN apt-get update && \
    apt-get install -y openssh-server \
            iputils-ping \
            ros-iron-joint-trajectory-controller \
            ros-iron-ros2-control \
            ros-iron-moveit-simple-controller-manager \
            ros-iron-moveit \
            ros-iron-moveit-servo


RUN useradd -m -s /usr/bin/bash student && \
    addgroup realtime && \
    usermod -a -G realtime student && \
    echo "source /opt/ros/franka/install/setup.bash" >> /home/student/.bashrc && \
    mkdir /run/sshd

# Need to allow the student
COPY limits.conf /etc/security/limits.conf

EXPOSE 22
CMD ["/usr/sbin/sshd", "-p", "9222", "-D"]