Skip to content

Commit

Permalink
Merge pull request #2069 from JdeRobot/issue-2068-b
Browse files Browse the repository at this point in the history
Added ROS2 miniRADI dockerfile
  • Loading branch information
ReyDoran authored May 18, 2023
2 parents f43366f + 63d9300 commit 9d16f94
Show file tree
Hide file tree
Showing 22 changed files with 799 additions and 0 deletions.
52 changes: 52 additions & 0 deletions scripts/ROS2/Dockerfile.academy
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
##################################################################################
# Create a miniRADI with RoboticsAcademy and some usefull scripts for developers #
##################################################################################

FROM jderobot/robotics-applications:base-2

# copy scripts for vnc displays
COPY ./start_vnc.sh /
COPY ./kill_all.sh /
COPY ./entrypoint.sh /
COPY ./start_vnc_gpu.sh /
COPY ./test/check_device.py /
# give execution permissions
RUN chmod +x /start_vnc.sh /kill_all.sh /entrypoint.sh /start_vnc_gpu.sh

# environment
COPY ./.env /.env


# RoboticsAcademy
RUN git clone --depth 10 https://github.com/JdeRobot/RoboticsAcademy.git -b master /RoboticsAcademy/

# Relocate RAM
RUN mkdir /RoboticsAcademy/src && mv /RoboticsApplicationManager/* /RoboticsAcademy/src

# build react_fronted
RUN cd /RoboticsAcademy/react_frontend/ && yarn install && yarn run build

# Django server
EXPOSE 8000
# Manager websocket
EXPOSE 7163

# Exercise websocket
EXPOSE 1905
# GUI websockets
EXPOSE 2303

# noVNC Console
EXPOSE 1108
# noVNC Gazebo
EXPOSE 6080
# noVNC Rviz
EXPOSE 6081
# noVNC GUI
EXPOSE 6082

# WebRtc
EXPOSE 1831

WORKDIR /
ENTRYPOINT ["./entrypoint.sh"]
46 changes: 46 additions & 0 deletions scripts/ROS2/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

############################################################
# Help #
############################################################
Help()
{
# Display Help
echo "Syntax: build.sh [-h] [-f]"
echo "options:"
echo "-h Print this Help."
echo "-f Force creation of base image. If ommited, the base image is created only if "
echo " it doestn exist."
echo
}

force_build=false
while getopts ":hf" option; do
case $option in
h) # display Help
echo "Generates RoboticsAcademy RADI image"
echo
Help
exit 0
;;
f)
force_build=true
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
Help
exit 1
;;
esac
done
shift $(($OPTIND - 1))

if $force_build || [[ "$(docker images -q jderobot/robotics-applications:pre-base 2> /dev/null)" == "" ]]; then
echo "BUILDING Jderobot PRE-BASE IMAGE ====================="
echo
docker build -f Dockerfile.pre-base -t jderobot/robotics-applications:pre-base .
fi

echo "BUILDING RoboticsAcademy BASE IMAGE ====================="
echo
docker build -f Dockerfile.base -t jderobot/robotics-applications:base .
56 changes: 56 additions & 0 deletions scripts/ROS2/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

usage="$(basename "$0") [-h] [--debug] [--logs] [--no-server]\n\n
optional arguments:\n
\t -h show this help message and exit\n
\t --debug run bash inside RADI\n
\t --logs record logs and run RADI\n
\t --no-server run RADI without webserver"

debug=false
log=false
webserver=true

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
-h | --help )
echo -e $usage
exit
;;
-d | --debug )
shift; debug=true
;;
-l | --logs )
shift; log=true
;;
-ns | --no-server )
webserver=false
;;
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi

if [ $webserver == true ]; then
runserver="python3 /RoboticsAcademy/manage.py runserver 0.0.0.0:8000"
else
runserver=""
fi
ros_setup=" source /.env && source ~/.bashrc && source /home/ws/install/setup.bash; "
runmanager="python3 RoboticsAcademy/manager/manager.py"
runram="python3 RoboticsAcademy/src/manager/manager/manager.py 0.0.0.0 7163"
root="cd /"

# TEST LOGS
if [ $log == true ]; then
DATE_TIME=$(date +%F-%H-%M) # FORMAT year-month-date-hours-mins
mkdir -p /root/.roboticsacademy/log/$DATE_TIME/
eval ${ros_setup}
script -q -c "$root & $runserver & $runram ;" /root/.roboticsacademy/log/$DATE_TIME/manager.log
cp -r /root/.ros/log/* /root/.roboticsacademy/log/$DATE_TIME
else
eval ${ros_setup}
if [ $debug == true ]; then
{ bash ; }
else
{ $root & $runserver & $runram ; }
fi
fi
Binary file added scripts/ROS2/gpu/turbovnc_3.0.3_amd64.deb
Binary file not shown.
Binary file added scripts/ROS2/gpu/virtualgl32_3.0.2_amd64.deb
Binary file not shown.
Binary file added scripts/ROS2/gpu/virtualgl_3.0.2_amd64.deb
Binary file not shown.
10 changes: 10 additions & 0 deletions scripts/ROS2/kill_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

pkill -9 -f gzserver
pkill -9 -f gzclient
pkill -9 -f xterm
pkill -9 -f rviz
pkill -9 -f rosmaster
pkill -9 -f xorg
pkill -9 -f websockify
pkill -9 -f python
67 changes: 67 additions & 0 deletions scripts/ROS2/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

usage() {
echo "usage: run.sh : tag must be specified
-t | --tag : docker image tag (required)
-v | --volume : path to a shared directory (optional)
-n | --name : name of container (optional)
-d | --debug : open a terminal inside container (optional)
--dev : use device inside container (optional) [specify device name]
-l | --logs : record logs and run RADI
-ns | --no-server : run RADI without webserver
example of usage:
./run.sh -t 4.3.0 -v /home/user/dir -n my_container -d --dev card0
"
}

unset logs server tag path device device_name volume name debug
serverport="-p 8000:8000"

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
-v | --volume )
shift;
path=$1
volume=true
;;
-n | --name )
shift;
name=$1
;;
-d | --debug )
debug=--debug
;;
--dev )
shift;
device="--device /dev/dri"
device_name=$1
;;
-t | --tag )
shift;
tag=$1
;;
-l | --logs )
logs="--logs"
;;
-ns | --no-server )
server="--no-server"
serverport=""
;;
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi

if [ -z $tag ]; then
usage
exit 1
fi

if [ -z $name ]; then
name=dockerRam_container
echo name not specified, container name will be: dockerRam_container
fi

if $volume && [ ! -z $path ] && [ -d $path ] ; then
docker run --name $name $device -e DRI_NAME=$device_name -v $path:/home/shared_dir --rm -it $serverport -p 2303:2303 -p 1905:1905 -p 8765:8765 -p 6080:6080 -p 6081:6081 -p 1108:1108 -p 6082:6082 -p 7163:7163 jderobot/robotics-academy:$tag $debug $logs $server
else
docker run --name $name $device -e DRI_NAME=$device_name --rm -it $serverport -p 2303:2303 -p 1905:1905 -p 8765:8765 -p 6080:6080 -p 6081:6081 -p 1108:1108 -p 6082:6082 -p 7163:7163 jderobot/robotics-academy:$tag $debug $logs $server
fi
64 changes: 64 additions & 0 deletions scripts/ROS2/run_cam.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

usage() {
echo "usage: run.sh : tag must be specified
-t | --tag : docker image tag (required)
-v | --volume : route to a shared directory (optional)
-n | --name : name of container (optional)
-d | --debug : open a terminal inside container (optional)
--dev : use device inside container (optional) [specify device name]
example of usage:
./run.sh -t 4.3.0 -v /home/user/dir -n my_container -d --dev card0
"
}


volume=false
name=""
tag=""
unset route
unset debug
unset device
unset device_name

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
-v | --volume )
shift;
route=$1
volume=true
;;
-n | --name )
shift;
name=$1
;;
-d | --debug )
debug=bash
;;
--dev )
shift;
device="--device /dev/dri"
device_name=$1
;;
-t | --tag )
shift;
tag=$1
;;
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi

if [ -z $tag ]; then
usage
exit 1
fi

if [ -z $name ]; then
name=dockerRam_container
echo name not specified, container name will be: dockerRam_container
fi

if $volume && [ ! -z $route ] && [ -d $route ] ; then
docker run --name $name $device -e DRI_NAME=$device_name -v $route:/home/shared_dir --rm -it -p 2303:2303 -p 1905:1905 -p 8765:8765 -p 6080:6080 -p 6081:6081 -p 1108:1108 -p 6082:6082 -p 7163:7163 --device /dev/video0:/dev/video0 jderobot/robotics-academy:$tag $debug
else
docker run --name $name $device -e DRI_NAME=$device_name --rm -it -p 2303:2303 -p 1905:1905 -p 8765:8765 -p 6080:6080 -p 6081:6081 -p 1108:1108 -p 6082:6082 -p 7163:7163 --device /dev/video0:/dev/video0 jderobot/robotics-academy:$tag $debug
fi
27 changes: 27 additions & 0 deletions scripts/ROS2/start_vnc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

usage() {
echo 'usage: /start_vnc.sh <display> <internal_port> <external_port>
example: >> /start_vnc.sh 0 5900 6080'
}

if [ $# -ne 3 ] ; then
usage
exit 1
fi

display=$1
internal_port=$2
external_port=$3

cd /
## xserver:
/usr/bin/Xorg -noreset -quiet +extension GLX +extension RANDR +extension RENDER -logfile ./xdummy.log -config ./xorg.conf :$display &
sleep 1
## lanzar servidor vnc
x11vnc -display :$display -quiet -nopw -forever -xkb -bg -rfbport $internal_port &
sleep 1
## lanzar cliente noVNC
/noVNC/utils/novnc_proxy --listen $external_port --vnc localhost:$internal_port &

export DISPLAY=:$display
22 changes: 22 additions & 0 deletions scripts/ROS2/start_vnc_gpu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

usage() {
echo 'usage: /start_vnc.sh <display> <internal_port> <external_port>
example: >> /start_vnc.sh 0 5900 6080'
}

if [ $# -ne 3 ] ; then
usage
exit 1
fi

display=$1
internal_port=$2
external_port=$3

cd /
# TurvoVNC (xserver + vncserver)
export VGL_DISPLAY=/dev/dri/card0 && export TVNC_WM=startlxde && /opt/TurboVNC/bin/vncserver :$display -geometry '1920x1080' -vgl -noreset -SecurityTypes None -rfbport $internal_port &
sleep 1
# lanzar cliente noVNC
/noVNC/utils/novnc_proxy --listen $external_port --vnc localhost:$internal_port &
Loading

0 comments on commit 9d16f94

Please sign in to comment.