From a9468357c6e9e7e4a9e8178537ddd8f5ef896b95 Mon Sep 17 00:00:00 2001 From: Kuba Kaflik Date: Thu, 29 Aug 2024 19:44:14 +0000 Subject: [PATCH] run Xvnc as a default entrypoint for dev container This is an alternative approach to run a VNC with xorg apps to expose Gazebo UI outside. VNC client app is required. --- .devcontainer/Dockerfile | 25 +++++++++++++------- .devcontainer/devcontainer.json | 3 --- .devcontainer/openmower_config.env | 2 +- .devcontainer/scripts/entrypoint.sh | 15 ++++++++++++ .devcontainer/scripts/post_create_command.sh | 2 ++ Makefile | 5 +--- 6 files changed, 35 insertions(+), 17 deletions(-) create mode 100755 .devcontainer/scripts/entrypoint.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0773965..716685f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,20 +3,24 @@ ARG USERNAME=dev ARG USER_UID=1001 ARG USER_GID=$USER_UID +ENV DISPLAY=:0 + +RUN apt-get update && apt-get install --no-install-recommends -y \ + xfonts-base \ + xauth \ + x11-xkb-utils \ + xkb-data \ + dbus-x11 \ + tigervnc-standalone-server + +COPY scripts/entrypoint.sh /entrypoint.sh + RUN groupadd --gid $USER_GID $USERNAME \ && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ && yes $USERNAME | passwd $USERNAME \ && usermod --shell /bin/bash $USERNAME \ && usermod -aG dialout $USERNAME -RUN apt-get update \ - && apt-get install -y ssh \ - python3-pip \ - curl \ - rsync \ - psmisc \ - && rm -rf /var/lib/apt/lists/* - RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME @@ -24,4 +28,7 @@ ENV SHELL /bin/bash RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/$USERNAME/.bashrc USER $USERNAME -CMD ["/bin/bash"] + +EXPOSE 5900 + +CMD ["/entrypoint.sh"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 96f99f9..12275fa 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -14,12 +14,9 @@ "workspaceMount": "source=${localWorkspaceFolder},target=/opt/ws,type=bind", "containerEnv": { "DISPLAY": ":0", - "ROS_LOCALHOST_ONLY": "1", - "ROS_DOMAIN_ID": "42" }, "runArgs": [ "--net=host", - "-e", "DISPLAY=${env:DISPLAY}" ], "customizations": { "vscode": { diff --git a/.devcontainer/openmower_config.env b/.devcontainer/openmower_config.env index bae3796..17d7e23 100644 --- a/.devcontainer/openmower_config.env +++ b/.devcontainer/openmower_config.env @@ -1,3 +1,3 @@ export OM_DATUM_LAT=-22.9 export OM_DATUM_LONG=-43.2 -export OM_MAP_PATH=/home/ws/.devcontainer/home/map.geojson \ No newline at end of file +export OM_MAP_PATH=/opt/ws/.devcontainer/home/map.geojson \ No newline at end of file diff --git a/.devcontainer/scripts/entrypoint.sh b/.devcontainer/scripts/entrypoint.sh new file mode 100755 index 0000000..e56510f --- /dev/null +++ b/.devcontainer/scripts/entrypoint.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +terminate_script() { + echo "Termination signal received, exiting..." + exit 1 +} + +trap terminate_script SIGINT + +if [ -z "$DISPLAY" ]; then + echo "DISPLAY not set, setting to :0" + DISPLAY=:0 +fi + +Xvnc -ac -pn -depth 24 $DISPLAY -rfbport=5900 -SecurityTypes=None -desktop=OpenMowerNext diff --git a/.devcontainer/scripts/post_create_command.sh b/.devcontainer/scripts/post_create_command.sh index ccd395f..2a3bec3 100644 --- a/.devcontainer/scripts/post_create_command.sh +++ b/.devcontainer/scripts/post_create_command.sh @@ -2,6 +2,8 @@ set -e +echo "Installing ROS packages..." + sudo apt update rosdep update make custom-deps deps diff --git a/Makefile b/Makefile index d4f0b6c..d2a7698 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,6 @@ all: custom-deps deps build .PHONY: deps build -dev-containers: - cd .devcontainer && docker-compose up -d - # turtlebot3_gazebo does not have a build on iron arm64 deps: rosdep install --from-paths ./ -i -y -r @@ -24,7 +21,7 @@ build: sim: killall -9 ruby || true - ros2 launch -d launch/sim.launch.py + ros2 launch launch/sim.launch.py run: ros2 launch launch/openmower.launch.py