Skip to content

Commit

Permalink
run Xvnc as a default entrypoint for dev container
Browse files Browse the repository at this point in the history
This is an alternative approach to run a VNC with xorg apps to expose Gazebo UI outside. VNC client app is required.
  • Loading branch information
jkaflik committed Aug 29, 2024
1 parent 9765418 commit a946835
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
25 changes: 16 additions & 9 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,32 @@ 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

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"]
3 changes: 0 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/openmower_config.env
Original file line number Diff line number Diff line change
@@ -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
export OM_MAP_PATH=/opt/ws/.devcontainer/home/map.geojson
15 changes: 15 additions & 0 deletions .devcontainer/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .devcontainer/scripts/post_create_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

echo "Installing ROS packages..."

sudo apt update
rosdep update
make custom-deps deps
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a946835

Please sign in to comment.