diff --git a/README.md b/README.md index d96d4e5..4d8c960 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,16 @@ -Docker 'n' rocker for quick and easy access to ROS2 (humble) and ROS1 (noetic) along with their GUI applications like Gazebo and rViz without the need for a local installation +Docker hacks for quick and easy access to ROS2 (humble) and ROS1 (noetic) along with their GUI applications like Gazebo and rViz without the need for a local installation ## Requirements * `docker` -* `pip` * `Linux` (not necessarily Debian-based) * `dialog` (optionally for interactive terminal UI) ## Instructions -* Make sure your system satisfies all the requirements. The installer script tries to remain distro-agnostic, thus does not install anything apart from `rocker` through `pip`). -* Run the `installer.bash` script with a single argument with the rosez version you need to install. e.g. `./installer.bash ros2ez`. You can also run it interactively with no arguments. For ros-ez versions < `1.7.0`, you must use one of the `ros_*installer.bash` script. There are multiple, one for each supported ROS distribution. +* Make sure your system satisfies all the requirements. The installer script tries to remain distro-agnostic, thus does not install anything. +* Run the `installer.bash` script with a single argument with the rosez version you need to install. e.g. `./installer.bash ros2ez`. You can also run it interactively with no arguments. For ros-ez versions < `1.7.0`, you must use one of the `ros_*installer.bash` scripts. There are multiple, one for each supported ROS distribution. * Run `. ~/.bashrc` or open a new terminal. * Run `ros2ez` for ROS2 or `rosez` for ROS1 followed by the command you want to run else you will be thrown in a shell inside the image (useful if autocomplete is required). @@ -40,6 +39,8 @@ or * [For versions >= `v1.6.0`] A ROS2 Foxy version is now available (with the `ros2ezf` command). Its image comes with built-in `ros1_bridge` support for *ez* ROS1-ROS2 integration. * [For versions >= `v1.6.1`] A deletion script has been included inside the `internal/deeper/` folder. It takes the version-to-delete as an argument. For example, `bash delete_version.bash ros2ezf` deletes the Foxy version for rosez. * [For versions >= `v1.7.0`] A new script to easily create systemd services was added. It can be used interactively using `dialog` or non-interactively by passing it 9 arguments. Running the `create_rosez_systemd_service.bash` with less than 9 args (but more than 0) will trigger a help message. Additionally the installation scripts have been merged into one, `installer.bash`. You can now use it interactively, or pass a single argument with the rosez version you need to install. e.g. `./installer.bash ros2ez` +* [For versions >= `v2.0.0`] Docker devices like sound and graphics are now manually handled. This version is **NOT** the same as the previous ones. This is a pretty substantial change, thus getting a major release. Externally nothing should change for the end user, but internally a lot has changed. OSRF's `rocker` is no longer utilized, making docker handling more versatile (but also fragile). + ## Tested platforms * EndeavourOS * Fedora 35 diff --git a/installer.bash b/installer.bash index 28117ad..fbe7b07 100755 --- a/installer.bash +++ b/installer.bash @@ -41,7 +41,6 @@ if [[ -z "$image_name" ]]; then done exit -1 fi -sudo pip install rocker==0.2.10 cd $SCRIPT_DIR need_rr=0 if ! id -nGz "$USER" | grep -qzxF "docker" diff --git a/internal/entrypoint.bash b/internal/entrypoint.bash index a1d420d..84907cc 100644 --- a/internal/entrypoint.bash +++ b/internal/entrypoint.bash @@ -1,4 +1,5 @@ #!/bin/bash +sudo find /home/rosez_user ! -user rosez_user -execdir sudo chown rosez_user:rosez_user {} \+ source /home/rosez_user/helpers.bash get_supported_versions lock_file=$LOCKFILE @@ -6,7 +7,6 @@ skip_compilation=$SKIPCOMPILATION rosversion="unknown" lockation="" wstxt="" -find /home/rosez_user ! -user rosez_user -execdir sudo chown rosez_user:rosez_user {} \+ for i in $(seq 0 $(( ${#distros[@]}-1 )) ); do if [ -f /opt/ros/"${distros[$i]}"/setup.bash ]; then rosversion="${distros[$i]}" diff --git a/internal/ros2_Dockerfile b/internal/ros2_Dockerfile index 96a5554..9f66fcd 100644 --- a/internal/ros2_Dockerfile +++ b/internal/ros2_Dockerfile @@ -1,3 +1,11 @@ +FROM nvidia/opengl:1.2-glvnd-devel-ubuntu22.04 as nvidia + +FROM osrf/ros:humble-desktop-full + +COPY --from=nvidia /usr/local /usr/local + +ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all + FROM osrf/ros:humble-desktop-full LABEL maintainer="George Stavrinos " @@ -42,18 +50,18 @@ RUN addgroup --gid $GROUP_ID rosez_user && adduser --disabled-password --gecos ' USER rosez_user RUN sudo chown -R rosez_user:rosez_user /home/rosez_user && rosdep update -VOLUME /opt/ros/humble -VOLUME /bin -VOLUME /etc -VOLUME /home -VOLUME /lib -VOLUME /lib64 -VOLUME /mnt -VOLUME /opt -VOLUME /root -VOLUME /run -VOLUME /sbin -VOLUME /srv -VOLUME /sys -VOLUME /usr -VOLUME /var +VOLUME /opt/ros/humble\ +/bin\ +/etc\ +/home\ +/lib\ +/lib64\ +/mnt\ +/opt\ +/root\ +/run\ +/sbin\ +/srv\ +/sys\ +/usr\ +/var diff --git a/internal/ros2_foxy_Dockerfile b/internal/ros2_foxy_Dockerfile index ad73a1d..88524a6 100644 --- a/internal/ros2_foxy_Dockerfile +++ b/internal/ros2_foxy_Dockerfile @@ -1,3 +1,11 @@ +FROM nvidia/opengl:1.2-glvnd-devel-ubuntu20.04 as nvidia + +FROM osrf/ros:foxy-ros1-bridge + +COPY --from=nvidia /usr/local /usr/local + +ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all + FROM osrf/ros:foxy-ros1-bridge LABEL maintainer="George Stavrinos " @@ -43,18 +51,18 @@ RUN addgroup --gid $GROUP_ID rosez_user && adduser --disabled-password --gecos ' USER rosez_user RUN sudo chown -R rosez_user:rosez_user /home/rosez_user && rosdep update -VOLUME /opt/ros/foxy -VOLUME /bin -VOLUME /etc -VOLUME /home -VOLUME /lib -VOLUME /lib64 -VOLUME /mnt -VOLUME /opt -VOLUME /root -VOLUME /run -VOLUME /sbin -VOLUME /srv -VOLUME /sys -VOLUME /usr -VOLUME /var +VOLUME /opt/ros/foxy\ +/bin\ +/etc\ +/home\ +/lib\ +/lib64\ +/mnt\ +/opt\ +/root\ +/run\ +/sbin\ +/srv\ +/sys\ +/usr\ +/var diff --git a/internal/ros_Dockerfile b/internal/ros_Dockerfile index b20bed0..f2f49a4 100644 --- a/internal/ros_Dockerfile +++ b/internal/ros_Dockerfile @@ -1,3 +1,11 @@ +FROM nvidia/opengl:1.2-glvnd-devel-ubuntu20.04 as nvidia + +FROM osrf/ros:noetic-desktop-full + +COPY --from=nvidia /usr/local /usr/local + +ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all + FROM osrf/ros:noetic-desktop-full LABEL maintainer="George Stavrinos " @@ -40,18 +48,18 @@ RUN addgroup --gid $GROUP_ID rosez_user && adduser --disabled-password --gecos ' USER rosez_user RUN sudo chown -R rosez_user:rosez_user /home/rosez_user && rosdep update -VOLUME /opt/ros/noetic -VOLUME /bin -VOLUME /etc -VOLUME /home -VOLUME /lib -VOLUME /lib64 -VOLUME /mnt -VOLUME /opt -VOLUME /root -VOLUME /run -VOLUME /sbin -VOLUME /srv -VOLUME /sys -VOLUME /usr -VOLUME /var +VOLUME /opt/ros/noetic\ +/bin\ +/etc\ +/home\ +/lib\ +/lib64\ +/mnt\ +/opt\ +/root\ +/run\ +/sbin\ +/srv\ +/sys\ +/usr\ +/var diff --git a/internal/ros_melodic_Dockerfile b/internal/ros_melodic_Dockerfile index a6fb4fa..8c48958 100644 --- a/internal/ros_melodic_Dockerfile +++ b/internal/ros_melodic_Dockerfile @@ -1,5 +1,11 @@ +FROM nvidia/opengl:1.2-glvnd-devel-ubuntu18.04 as nvidia + FROM osrf/ros:melodic-desktop-full +COPY --from=nvidia /usr/local /usr/local + +ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all + LABEL maintainer="George Stavrinos " RUN mkdir -p /opt/ros/catkin_ws/src && apt-get update && apt-get full-upgrade -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \ @@ -40,18 +46,18 @@ RUN addgroup --gid $GROUP_ID rosez_user && adduser --disabled-password --gecos ' USER rosez_user RUN sudo chown -R rosez_user:rosez_user /home/rosez_user && rosdep update -VOLUME /opt/ros/melodic -VOLUME /bin -VOLUME /etc -VOLUME /home -VOLUME /lib -VOLUME /lib64 -VOLUME /mnt -VOLUME /opt -VOLUME /root -VOLUME /run -VOLUME /sbin -VOLUME /srv -VOLUME /sys -VOLUME /usr -VOLUME /var +VOLUME /opt/ros/melodic\ +/bin\ +/etc\ +/home\ +/lib\ +/lib64\ +/mnt\ +/opt\ +/root\ +/run\ +/sbin\ +/srv\ +/sys\ +/usr\ +/var diff --git a/internal/rosez_exec.bash b/internal/rosez_exec.bash index b34a395..c6f96e7 100755 --- a/internal/rosez_exec.bash +++ b/internal/rosez_exec.bash @@ -80,7 +80,7 @@ done if [ -z "$gpu_param" ]; then if grep -q "nvidia" <<< "$gpu_string" || grep -q "Nvidia" <<< "$gpu_string" || grep -q "NVIDIA" <<< "$gpu_string" then - gpu_param="--nvidia" + gpu_param="--gpus all" elif grep -q "intel" <<< "$gpu_string" || grep -q "Intel" <<< "$gpu_string" || grep -q "INTEL" <<< "$gpu_string" then gpu_param="--device /dev/dri/card0" @@ -136,32 +136,27 @@ if [ ! -d $ssh_folder ]; then mkdir $ssh_folder fi intermediate_error_handler $? -sound="--pulse" +sound="-v /run/user/$userid/pulse:/run/user/$userid/pulse --device /dev/snd -e PULSE_SERVER=unix:/run/user/$userid/pulse/native -v /run/user/$userid/pulse/native:/run/user/$userid/pulse/native" if [ $no_sound -gt 0 ]; then sound="" fi -x=""$(rocker --mode dry-run --network host --x11 $sound $gpu_param --volume $rosez_vol-bin:/bin --volume $rosez_vol-etc:/etc/ --volume $rosez_vol-etc:/etc/ --volume $rosez_vol-home:/home/ --volume $rosez_vol-lib:/lib/ --volume $rosez_vol-lib64:/lib64/ --volume $rosez_vol-mnt:/mnt/ --volume $rosez_vol-opt:/opt/ --volume $rosez_vol-root:/root/ --volume $rosez_vol-run:/run/ --volume $rosez_vol-sbin:/sbin/ --volume $rosez_vol-srv:/srv/ --volume $rosez_vol-sys:/sys/ --volume $rosez_vol-usr:/usr --volume $rosez_vol-var:/var --volume $rosez_vol:/opt/ros/$ros --volume $SCRIPT_DIR/../includes/$rosws_file:/opt/ros/$rosws_file $volumes $SCRIPT_DIR/../internal/entrypoint.bash:/home/rosez_user/.bashrc --volume /dev:/dev --volume $bloom_file:/home/rosez_user/.config/bloom --volume $gitconfig_file:/home/rosez_user/.gitconfig --volume $ssh_folder:/home/rosez_user/.ssh --volume $SCRIPT_DIR/supported_versions.txt:/home/rosez_user/supported_versions.txt --volume $SCRIPT_DIR/helpers.bash:/home/rosez_user/helpers.bash --volume /:$HOME/.$rosez_vol -- $ros_image:latest | tail -n 1 | sed -e "s#-v $(pwd)/$rosez_vol#-v $rosez_vol#g") -echo $x -intermediate_error_handler $? -xauthf="$((echo \"$x\") | grep -E -o '/tmp/.docker[a-zA-Z0-9_-]+.xauth' | head -1)" -intermediate_error_handler $? +it="-it" +if [ $non_interactive -gt 0 ]; then + it="" +fi +userid=$(id -u) +xauthf="/tmp/.$ros_image-$now.xauth" touch $xauthf intermediate_error_handler $? /bin/bash -c "xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $xauthf nmerge -" intermediate_error_handler $? -cl="" +x="docker run --rm $it -u $userid --ipc=host --privileged --network host $gpu_param $sound --group-add dialout --group-add video --group-add audio -v $rosez_vol-bin:/bin -v $rosez_vol-etc:/etc/ -v $rosez_vol-etc:/etc/ -v $rosez_vol-home:/home/ -v $rosez_vol-lib:/lib/ -v $rosez_vol-lib64:/lib64/ -v $rosez_vol-mnt:/mnt/ -v $rosez_vol-opt:/opt/ -v $rosez_vol-root:/root/ -v $rosez_vol-run:/run/ -v $rosez_vol-sbin:/sbin/ -v $rosez_vol-srv:/srv/ -v $rosez_vol-sys:/sys/ -v $rosez_vol-usr:/usr -v $rosez_vol-var:/var -v $rosez_vol:/opt/ros/$ros -v $SCRIPT_DIR/../includes/$rosws_file:/opt/ros/$rosws_file $volumes -v $SCRIPT_DIR/entrypoint.bash:/home/rosez_user/.bashrc -v /dev:/dev -v $bloom_file:/home/rosez_user/.config/bloom -v $gitconfig_file:/home/rosez_user/.gitconfig -v $ssh_folder:/home/rosez_user/.ssh -v $SCRIPT_DIR/supported_versions.txt:/home/rosez_user/supported_versions.txt -v $SCRIPT_DIR/helpers.bash:/home/rosez_user/helpers.bash -v /:$HOME/.$rosez_vol -e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 -e XAUTHORITY=$xauthf -v $xauthf:$xauthf -v /tmp/.X11-unix:/tmp/.X11-unix -v /etc/localtime:/etc/localtime:ro $ros_image:latest" +intermediate_error_handler $? extras="env $ENV LOCKFILE=$lock_file SKIPCOMPILATION=$skip_compilation /bin/bash" if [ $# -gt 0 ]; then extras=$extras" -c \"source /home/rosez_user/.bashrc && $* \"" fi x="$x $extras" -userid=$(id -u) -groupid=$(id -g) -it="-it" -if [ $non_interactive -gt 0 ]; then - it="" -fi -x=${x/docker run --rm -it/docker run --rm $it -u $userid --ipc=host --privileged} intermediate_error_handler $? printf "Executing:\n---\n$x\n---\n" eval "$x"