From 178f2ce809430cf40269e8926268d56dab915d05 Mon Sep 17 00:00:00 2001
From: rschoene <rene.schoene@tu-dresden.de>
Date: Wed, 20 Jul 2022 15:16:54 +0200
Subject: [PATCH] working on docker setup and readme

---
 README.md                                    |  27 +++--
 docker-compose.yml                           |  56 +++++++---
 robotic-controller/Dockerfile-vnc            | 112 +++++++++++++++++++
 robotic-controller/src/ccf                   |   2 +-
 robotic-controller/src/ccf_immersive_sorting |   2 +-
 robotic-controller/vnc/30-nofilelimit.conf   |   4 +
 robotic-controller/vnc/copyws.sh             |   7 ++
 robotic-controller/vnc/run1.sh               |   4 +
 robotic-controller/vnc/run2.sh               |   4 +
 ros3rag                                      |   2 +-
 web-ros3rag                                  |   2 +-
 11 files changed, 195 insertions(+), 27 deletions(-)
 create mode 100644 robotic-controller/Dockerfile-vnc
 create mode 100644 robotic-controller/vnc/30-nofilelimit.conf
 create mode 100644 robotic-controller/vnc/copyws.sh
 create mode 100644 robotic-controller/vnc/run1.sh
 create mode 100644 robotic-controller/vnc/run2.sh

diff --git a/README.md b/README.md
index a24ad21..7e8593e 100644
--- a/README.md
+++ b/README.md
@@ -2,25 +2,34 @@
 
 ## Docker
 
-To quickly run the graphical example applications, you can use Docker. For development purposes, please use the regular installation
-instructions further below in this document. Please note that the setup uses vnc and thus offers limited graphics performance.
+To quickly run the graphical example applications, you can use Docker.
+Please note that the setup uses vnc and thus offers limited graphics performance.
 
-:warning: TODO: check what is needed for VNC setup
+:warning: TODO: check what is needed for VNC setup, and check everything labelled with "(OLD)"
 
 - Install Docker and docker-compose for your system (for Windows and Mac OS, install Docker Desktop)
-- Build the container `docker build --tag cgvsim .`
-- Run the container: `docker run -it -p 6080:80 --rm cgvsim`. A webserver is run inside the container that is exposed to port `6080` on your system.
-- Open `http://localhost:6080` in a web browser
+- (OLD) Build the container `docker build --tag cgvsim .`
+- (OLD) Run the container: `docker run -it -p 6080:80 --rm cgvsim`. A webserver is run inside the container that is exposed to port `6080` on your system.
+- (OLD) Open `http://localhost:6080` in a web browser
 
-## Installation
+## Installation and Preparation
 
 - Clone this repo and its submodules:
     - `git clone --recurse-submodules https://git-st.inf.tu-dresden.de/ceti/ros/models2022.git models2022`
     - (as a project member with a registered ssh key: `git clone --recurse-submodules git@git-st.inf.tu-dresden.de:ceti/ros/models2022.git models2022`)
     - change into the workspace `cd models2022`
 - Prepare/Build all docker images: `docker-compose build`
+
+## Running the Case Study
+
 - (Optional) Use the Web UI to observe MQTT message and view the runtime model of place B
     - `docker-compose up -d web_rag`
     - Open your browser at <http://0.0.0.0:8050/>
-- Start the case study
-    - `docker-compose up [-d] coordinator` (the `-d` flag is optional to run the coordinator in the background)
+- (OLD) Start the case study
+    - (OLD) `docker-compose up [-d] coordinator` (the `-d` flag is optional to run the coordinator in the background)
+
+## Experiment with RagConnect
+
+-> Still TODO
+
+To experiment with a less complex scenario and verify the functionality of the tool RagConnect itself, you can use the 
diff --git a/docker-compose.yml b/docker-compose.yml
index 386ae59..1a55769 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,31 +3,59 @@ services:
   # ros_core:
   #   build: "robotic-controller"
   #   user: "user"
-  #   command: ['/entrypoint.sh', 'roscore']
+  #   command: ['roscore']
 
   # ros_place_a:
   #   build: "robotic-controller"
   #   user: "user"
   #   # TODO: update command
-  #   command: ['/entrypoint.sh', 'rosrun', 'cgv_connector', 'dummy_rag_connector']
+  #   command: ['rosrun', 'cgv_connector', 'dummy_rag_connector']
 
   ros_place_b1:
-    build: "robotic-controller"
-    user: "user"
-    command: ['/entrypoint.sh', 'roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-1-placeworld.launch']
+    # build: "robotic-controller"
+    build:
+      context: robotic-controller
+      dockerfile: Dockerfile-vnc
+    # command: ['roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-1-placeworld.launch']
+    # command: ['roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-1-placeworld.launch', 'use_rviz:=false', 'mqtt_server:="tcp://mosquitto:1883"']
+    # deploy:
+    #   resources:
+    #     limits:
+    #       cpus: '0.50'
+    #       memory: 2G
+    volumes:
+      # - "/tmp/.X11-unix:/tmp/.X11-unix:rw"
+      # - "/tmp/.docker.xauth:/tmp/.docker.xauth:rw"
+      - "./ros_place_b1_logs/:/home/root/.ros/log"
+    # environment:
+    #   - "XAUTHORITY=/tmp/.docker.xauth"
+    #   - "DISPLAY=$DISPLAY"
+    # devices:
+    #   - "/dev/dri"
+    # user: "user"
+    ports:
+      - "6081:80"
 
   ros_place_b2:
     build: "robotic-controller"
-    command: ['/entrypoint.sh', 'roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-2-placeworld.launch']
+    # command: ['roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-2-placeworld.launch']
+    # deploy:
+    #   resources:
+    #     limits:
+    #       cpus: '0.50'
+    #       memory: 2G
     volumes:
-      - "/tmp/.X11-unix:/tmp/.X11-unix:rw"
-      - "/tmp/.docker.xauth:/tmp/.docker.xauth:rw"
-    environment:
-      - "XAUTHORITY=/tmp/.docker.xauth"
-      - "DISPLAY=$DISPLAY"
-    devices:
-      - "/dev/dri"
-    user: "ros"
+      # - "/tmp/.X11-unix:/tmp/.X11-unix:rw"
+      # - "/tmp/.docker.xauth:/tmp/.docker.xauth:rw"
+      - "./ros_place_b2_logs/:/home/root/.ros/log"
+    # environment:
+    #   - "XAUTHORITY=/tmp/.docker.xauth"
+    #   - "DISPLAY=$DISPLAY"
+    # devices:
+    #   - "/dev/dri"
+    # user: "user"
+    ports:
+      - "6082:80"
 
   coordinator:
     privileged: true
diff --git a/robotic-controller/Dockerfile-vnc b/robotic-controller/Dockerfile-vnc
new file mode 100644
index 0000000..101df31
--- /dev/null
+++ b/robotic-controller/Dockerfile-vnc
@@ -0,0 +1,112 @@
+FROM dorowu/ubuntu-desktop-lxde-vnc:focal
+
+# Get public key for google
+RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
+
+# Fix dirmngr
+RUN apt-get purge dirmngr -y && apt-get update && apt-get install dirmngr -y
+
+# Adding keys for ROS
+RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
+RUN sed -i 's/^deb/deb [trusted=yes]/' /etc/apt/sources.list.d/ros-latest.list
+
+# Installing ROS
+# RUN apt-get update && apt-get install -y ros-melodic-desktop-full wget nano python-rosdep
+# RUN apt-get install -y \
+      # ros-melodic-libfranka python-catkin-tools libeigen3-dev 
+RUN apt-get update && apt-get install -y \
+    ros-noetic-ros-core=1.5.0-1* \
+    python3-osrf-pycommon \
+    python3-catkin-tools \
+    build-essential \
+    protobuf-compiler \
+    libprotobuf-dev \
+    python3-rosdep \
+    ca-certificates
+
+# update rosdep dependencies manually to speed up process
+RUN apt-get update && apt-get install -y \
+    # ros-noetic-gazebo-msgs \
+    libsdformat9-dev \
+    # ros-noetic-gazebo-ros \
+    ros-noetic-xacro \
+    ros-noetic-tf2 \
+    ros-noetic-moveit-ros-planning-interface \
+    ros-noetic-franka-gripper \
+    ros-noetic-controller-manager \
+    ros-noetic-effort-controllers \
+    # ros-noetic-gazebo-plugins \
+    # ros-noetic-gazebo-ros-control \
+    ros-noetic-joint-state-controller \
+    ros-noetic-joint-state-publisher \
+    ros-noetic-joint-trajectory-controller \
+    ros-noetic-robot-state-publisher \
+    ros-noetic-tf \
+    ros-noetic-moveit-simple-controller-manager \
+    ros-noetic-moveit-core \
+    ros-noetic-moveit-ros-perception \
+    ros-noetic-moveit-visual-tools \
+    ros-noetic-controller-interface \
+    ros-noetic-hardware-interface \
+    ros-noetic-moveit-ros-move-group \
+    ros-noetic-moveit-fake-controller-manager \
+    ros-noetic-moveit-kinematics \
+    ros-noetic-moveit-planners-ompl \
+    ros-noetic-moveit-ros-visualization \
+    ros-noetic-joint-state-publisher-gui \
+    libnng1 \
+    libnng-dev
+
+RUN apt-get dist-upgrade -y
+
+# create initial workspace and desktop dir
+RUN mkdir -p /root/workspace /root/Desktop/
+
+# create symlink on desktop
+RUN ln -s /usr/share/applications/lxterminal.desktop /root/Desktop/lxterminal.desktop
+
+# set ROS distro
+ENV ROS_DISTRO=noetic
+
+# copy workspace from host
+WORKDIR /root/workspace
+COPY ./src /root/workspace/src
+
+# initialize dependencies
+RUN rosdep init && rosdep update && rosdep install --from-paths /root/workspace/ -i -r -y
+
+# build
+RUN /bin/bash -c "source /opt/ros/noetic/setup.bash && catkin build"
+
+# setup script to run for each bash (sourcing workspace and cd into it)
+RUN /bin/bash -c "echo -e 'umask 000\n \
+      ulimit -Sn 1024\n \
+      ulimit -Hn 524288\n \
+      source /opt/ros/noetic/setup.bash\n \
+      source /root/workspace/devel/setup.bash\n \
+      cd /root/Desktop/ros_ws/\n' >> /root/.bashrc "
+
+# create working workspace
+RUN mkdir -p /root/Desktop/ros_ws
+
+# prepare script to copy workspace
+COPY vnc/copyws.sh /root/copyws.sh
+RUN chmod a+x /root/copyws.sh
+
+# limit file descriptors, see https://answers.ros.org/question/336963/rosout-high-memory-usage/?answer=340381#post-id-340381
+COPY vnc/30-nofilelimit.conf /etc/security/limits.d/30-nofilelimit.conf
+
+# prepare run scripts
+COPY vnc/run1.sh /root/Desktop/run1.sh
+COPY vnc/run2.sh /root/Desktop/run2.sh
+RUN chmod a+x /root/Desktop/run1.sh
+RUN chmod a+x /root/Desktop/run2.sh
+
+RUN catkin config --extend /opt/ros/noetic
+ENV OPENBOX_ARGS --startup "/root/copyws.sh"
+
+# open ports. 11311: ROS, 6576: nng
+EXPOSE 11311/tcp
+EXPOSE 6576/tcp
+
+VOLUME /root/Desktop/ros_ws
diff --git a/robotic-controller/src/ccf b/robotic-controller/src/ccf
index 872b968..b5423ef 160000
--- a/robotic-controller/src/ccf
+++ b/robotic-controller/src/ccf
@@ -1 +1 @@
-Subproject commit 872b968eafb37070e020ca047f14a474a75a99e8
+Subproject commit b5423eff2a7f59b55e6a7e1cd3b60a32d46817b6
diff --git a/robotic-controller/src/ccf_immersive_sorting b/robotic-controller/src/ccf_immersive_sorting
index 5afd0e4..ff4b301 160000
--- a/robotic-controller/src/ccf_immersive_sorting
+++ b/robotic-controller/src/ccf_immersive_sorting
@@ -1 +1 @@
-Subproject commit 5afd0e429aa0902bc4a9556cf050bada890f848e
+Subproject commit ff4b30174dff8d1d0718d435f6788ed2e0b5df58
diff --git a/robotic-controller/vnc/30-nofilelimit.conf b/robotic-controller/vnc/30-nofilelimit.conf
new file mode 100644
index 0000000..0000207
--- /dev/null
+++ b/robotic-controller/vnc/30-nofilelimit.conf
@@ -0,0 +1,4 @@
+#<domain>  <type>  <item>  <value>
+
+*          soft    nofile  1024
+*          hard    nofile  524288
diff --git a/robotic-controller/vnc/copyws.sh b/robotic-controller/vnc/copyws.sh
new file mode 100644
index 0000000..043d024
--- /dev/null
+++ b/robotic-controller/vnc/copyws.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -z "$(ls -A /root/Desktop/ros_ws)" ]; then
+   echo "Copying workspace..."
+   cp /root/workspace/* /root/Desktop/ros_ws -r
+   chmod a+rwx /root/Desktop/ros_ws/ -R
+fi
diff --git a/robotic-controller/vnc/run1.sh b/robotic-controller/vnc/run1.sh
new file mode 100644
index 0000000..fc80153
--- /dev/null
+++ b/robotic-controller/vnc/run1.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+source /opt/ros/noetic/setup.bash
+source /root/workspace/devel/setup.bash
+roslaunch ccf_immersive_sorting noop-sim-cell_ceti-table-1-placeworld.launch mqtt_server:=tcp://mosquitto:1883
diff --git a/robotic-controller/vnc/run2.sh b/robotic-controller/vnc/run2.sh
new file mode 100644
index 0000000..c809408
--- /dev/null
+++ b/robotic-controller/vnc/run2.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+source /opt/ros/noetic/setup.bash
+source /root/workspace/devel/setup.bash
+roslaunch ccf_immersive_sorting noop-sim-cell_ceti-table-2-placeworld.launch mqtt_server:=tcp://mosquitto:1883
diff --git a/ros3rag b/ros3rag
index 3197411..e0bc953 160000
--- a/ros3rag
+++ b/ros3rag
@@ -1 +1 @@
-Subproject commit 31974114f8867e38907a5100ad0b9a33f78aa076
+Subproject commit e0bc953e001d51a3c97442684a4abeabb06ffc2c
diff --git a/web-ros3rag b/web-ros3rag
index 5252118..d51a74f 160000
--- a/web-ros3rag
+++ b/web-ros3rag
@@ -1 +1 @@
-Subproject commit 525211869b81bbaaab0e56f267dd5c831f709720
+Subproject commit d51a74f17e25baf54b50b280b99037fe4934241c
-- 
GitLab