From 8c2dbf70eeb9c832060811e93b7f5d412d4cdf8d Mon Sep 17 00:00:00 2001 From: franklinselva Date: Thu, 26 Sep 2024 17:46:02 +0200 Subject: [PATCH 1/2] Add docker file for GUI stack Related to #188 - Add docker file for GUI stack - Add build.sh at root level to build GUI stack - Add run.sh at root level to run GUI stack --- Dockerfile.gui | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 37 +++++++++++++++++++++++++++++++ run.sh | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 Dockerfile.gui create mode 100755 build.sh create mode 100755 run.sh diff --git a/Dockerfile.gui b/Dockerfile.gui new file mode 100644 index 0000000..5089a48 --- /dev/null +++ b/Dockerfile.gui @@ -0,0 +1,60 @@ +FROM ros:humble-ros-core-jammy + +ARG DEBIAN_FRONTEND=noninteractive + +ENV RMW_IMPLEMENTATION=rmw_cyclonedds_cpp +ENV ROS_DISTRO=humble +ENV USERNAME=spaceros-user +ENV HOME=/home/spaceros-user +ENV IGNITION_VERSION=fortress +ENV GZ_VERSION=fortress + +# Install dependencies +RUN apt update && apt install -y ros-${ROS_DISTRO}-rmw-cyclonedds-cpp \ + python3-rosdep python3-colcon-common-extensions \ + wget \ + curl \ + && apt clean \ + && rm -rf /var/lib/apt/lists/* + +# Run rosdep +RUN rosdep init \ + && rosdep update + +RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg\ + && echo "deb [arch=amd64 signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null + +# Install Gazebo +RUN apt-get update -qq \ + && apt-get install -y \ + gz-${GZ_VERSION} \ + libgz-sim7 \ + libgz-transport12 \ + libgz-gui7 \ + build-essential\ + ros-${ROS_DISTRO}-rcl-interfaces\ + ros-${ROS_DISTRO}-rclcpp\ + ros-${ROS_DISTRO}-builtin-interfaces\ + ros-${ROS_DISTRO}-ros-gz\ + ros-${ROS_DISTRO}-sdformat-urdf\ + ros-${ROS_DISTRO}-vision-msgs\ + ros-${ROS_DISTRO}-actuator-msgs\ + ros-${ROS_DISTRO}-image-transport\ + ros-${ROS_DISTRO}-xacro\ + ros-${ROS_DISTRO}-ros-ign-gazebo \ + && rm -rf /var/lib/apt/lists/* + + +# Install Rviz2 +RUN apt-get update -qq \ + && apt-get install -y \ + ros-${ROS_DISTRO}-rviz2 \ + ros-${ROS_DISTRO}-moveit-ros-visualization \ + ros-${ROS_DISTRO}-nav2-rviz-plugins \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR ${HOME} + +RUN echo "source /opt/ros/humble/setup.bash" >> ${HOME}/.bashrc + +CMD ign gazebo \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..fadf3df --- /dev/null +++ b/build.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +IMAGE_NAME="osrf/ros2" + +set -e + +# Build the stack + +# Helper function +function help { + echo "Usage: $0 stack-name [options]" + echo "USAGE" + echo "-h, --help: display this help message" + echo " stack-name: the name of the stack to build. Must be one of the following:" + echo " - gui" + echo " - nav2" + echo " - moveit2" +} + +function build_gui { + echo "Building GUI stack" + docker build -t $IMAGE_NAME:gui -f Dockerfile.gui . +} + +# Parse command line arguments +if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + help + exit 0 +fi + +if [ "$1" == "gui" ]; then + build_gui +else + echo "Invalid stack name" + help + exit 1 +fi diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..82cb762 --- /dev/null +++ b/run.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +IMAGE_NAME="osrf/ros2" +CONTAINER_NAME="space-ros" + +set -e + +# Helper function +function help { + echo "Usage: $0 stack-name [options]" + echo "USAGE" + echo "-h, --help: display this help message" + echo " stack-name: the name of the stack to build. Must be one of the following:" + echo " - gui" + echo " - nav2" + echo " - moveit2" +} + +function run_gui { + echo "Running GUI stack" + docker run -it --rm --name $CONTAINER_NAME-gui \ + -e DISPLAY=$DISPLAY \ + -e QT_X11_NO_MITSHM=1 \ + -e NVIDIA_VISIBLE_DEVICES=all \ + -e NVIDIA_DRIVER_CAPABILITIES=all \ + -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \ + -e __NV_PRIME_RENDER_OFFLOAD=1 \ + -e __GLX_VENDOR_LIBRARY_NAME=nvidia \ + -e RMW_IMPLEMENTATION=rmw_cyclonedds_cpp \ + -e XAUTHORITY=$XAUTHORITY \ + -v /run/user:/run/user:ro \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + $IMAGE_NAME:gui + +} + +# Parse command line arguments +if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + help + exit 0 +fi + +if [ "$1" == "gui" ]; then + run_gui +else + echo "Invalid stack name" + help + exit 1 +fi From 726bf997c97b1d7a1490b6b9398955fb3cdb351f Mon Sep 17 00:00:00 2001 From: franklinselva Date: Thu, 26 Sep 2024 17:52:07 +0200 Subject: [PATCH 2/2] Update README.md for building and running stacks Related to #188 y --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 522c3c7..0832faf 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,42 @@ See individual template directories for details. * [rtems](./rtems) * [space_robots](./space_robots) * [zynq_rtems](./zynq_rtems) + + +### Build stacks + +To build the docker images available in the stack, run the following command: + +```bash +# To show the available options +./build.sh -help +# Usage: ./build.sh stack-name [options] +# USAGE +# -h, --help: display this help message +# stack-name: the name of the stack to build. Must be one of the following: +# - gui +# - nav2 +# - moveit2 + +# To build GUI stack +./build.sh gui +``` + +### Starting a stack container + +To run the docker images available in the stack, run the following command: + +```bash +# To show the available options +./run.sh -help +# Usage: ./build.sh stack-name [options] +# USAGE +# -h, --help: display this help message +# stack-name: the name of the stack to build. Must be one of the following: +# - gui +# - nav2 +# - moveit2 + +# To run GUI stack +./run.sh gui +```