From 101c0a85e99078e04087359e74d323c6497aca0e Mon Sep 17 00:00:00 2001 From: Marina Moreira <67443181+marinagmoreira@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:49:39 -0700 Subject: [PATCH] Remote docker vscode (#779) * set up astrobee_vnc docker example * adding multiple devcontainer configurations; fizing documentation link * adding all of the remote docker files * working with devcontainer remotely * adding documentation for both methods and devcontainer * adding line at the end * adding running ssh script * removing docker remote folder and just have the vscode method * updating docs for more clear display configuration --------- Co-authored-by: Trey Smith --- .devcontainer/{ => local}/Dockerfile | 0 .devcontainer/{ => local}/devcontainer.json | 2 +- .devcontainer/remote/Dockerfile | 31 +++++++++++++++++++ .devcontainer/remote/devcontainer.json | 26 ++++++++++++++++ INSTALL.md | 2 +- doc/documentation_local.html | 2 ++ scripts/docker/readme.md | 33 +++++++++------------ scripts/start_vnc.sh | 21 +++++++++++++ 8 files changed, 96 insertions(+), 21 deletions(-) rename .devcontainer/{ => local}/Dockerfile (100%) rename .devcontainer/{ => local}/devcontainer.json (99%) create mode 100644 .devcontainer/remote/Dockerfile create mode 100644 .devcontainer/remote/devcontainer.json create mode 100644 doc/documentation_local.html create mode 100755 scripts/start_vnc.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/local/Dockerfile similarity index 100% rename from .devcontainer/Dockerfile rename to .devcontainer/local/Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/local/devcontainer.json similarity index 99% rename from .devcontainer/devcontainer.json rename to .devcontainer/local/devcontainer.json index 3f67b120c4..290237ccf6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/local/devcontainer.json @@ -41,4 +41,4 @@ ], "workspaceMount": "source=${localWorkspaceFolder},target=/src/astrobee/src,type=bind", "workspaceFolder": "/src/astrobee/src" -} \ No newline at end of file +} diff --git a/.devcontainer/remote/Dockerfile b/.devcontainer/remote/Dockerfile new file mode 100644 index 0000000000..72ed3060e2 --- /dev/null +++ b/.devcontainer/remote/Dockerfile @@ -0,0 +1,31 @@ +ARG UBUNTU_VERSION=20.04 +ARG REMOTE=ghcr.io/nasa +FROM ${REMOTE}/astrobee:latest-ubuntu${UBUNTU_VERSION} +ENV DEBIAN_FRONTEND=dialog + +# Rationale for packages: +# xvfb: X server that doesn't need GPU or physical display +# x11vnc: VNC server that shares xvfb display with external VNC clients +# xfce4: lightweight window manager +# dbus-x11: inter-process communication needed by xfce +# x11-apps: X11 apps to demo such as xeyes +# x11-utils: debugging commands such as xdpyinfo +# x11-xserver-utils: setup commands such as xset + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + dbus-x11 \ + x11-apps \ + x11-utils \ + x11-xserver-utils \ + x11vnc \ + xfce4 \ + xvfb \ + && rm -rf /var/lib/apt/lists/* + +RUN ls -l + +CMD ["/src/astrobee/src/scripts/start_vnc.sh"] + +# Expose VNC server's port +EXPOSE 5900 diff --git a/.devcontainer/remote/devcontainer.json b/.devcontainer/remote/devcontainer.json new file mode 100644 index 0000000000..a679c417b0 --- /dev/null +++ b/.devcontainer/remote/devcontainer.json @@ -0,0 +1,26 @@ +{ + "dockerFile": "Dockerfile", + "build": { + "args": { + "WORKSPACE": "${containerWorkspaceFolder}" + } + }, + "remoteUser": "root", + "overrideCommand": false, + "forwardPorts": [ + 5900 + ], + "runArgs": [ + "-ti", + "--rm", + "--cap-add=SYS_PTRACE", + "--security-opt=seccomp:unconfined", + "--security-opt=apparmor:unconfined" + ], + "containerEnv": { + "DISPLAY": ":0", + "LIBGL_ALWAYS_SOFTWARE": "1" // Needed for software rendering of opengl + }, + "workspaceMount": "source=${localWorkspaceFolder},target=/src/astrobee/src,type=bind", + "workspaceFolder": "/src/astrobee/src" +} diff --git a/INSTALL.md b/INSTALL.md index fed41de0f5..23f96bd6cc 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -53,7 +53,7 @@ development). We do not support running Astrobee Robot Software on 32-bit system There is also experimental support for using the Visual Studio Code Dev Containers plugin to access an integrated development environment running inside the Docker container! -For much more discussion, see: \subpage install-docker. +For much more discussion, see: \subpage install-docker ## Option 2: Install in your native OS / Virtual Machine diff --git a/doc/documentation_local.html b/doc/documentation_local.html new file mode 100644 index 0000000000..cfd3290122 --- /dev/null +++ b/doc/documentation_local.html @@ -0,0 +1,2 @@ + + diff --git a/scripts/docker/readme.md b/scripts/docker/readme.md index 29d18df722..bb412c92ea 100644 --- a/scripts/docker/readme.md +++ b/scripts/docker/readme.md @@ -6,12 +6,10 @@ Before running these instructions, make sure you visit the main Astrobee INSTALL - Check the system requirements. - Follow the Docker-option install steps 1-2, install Docker and check out the Astrobee Robot Software (ARS). -# Option 1: Using Visual Studio Code (experimental!) +# Option 1: Using Visual Studio Code You may find it helpful to use VSCode's Docker integration to help you interactively develop inside a Docker container. -Our team is tentatively moving in the direction of encouraging all developers to work this way, but our VSCode approach is still considered highly experimental and could change a lot. - ## Install VSCode and the Dev Containers plugin There are many valid ways to install VSCode. These commands are for an APT-style installation on Ubuntu: @@ -31,16 +29,19 @@ code --install-extension ms-vscode-remote.remote-containers ## Use VSCode to open the folder inside the Docker container -You can open the Astrobee folder inside the Docker container like this ([per the discussion here](https://github.com/microsoft/vscode-remote-release/issues/2133#issuecomment-1212180962)): +Tthe Dev Containers plugin will download a pre-built ARS Docker image from our official repository, start it running, and provide you with a development environment running inside the container. -```bash -cd $ASTROBEE_WS/src -(path=$(pwd) && p=$(printf "%s" "$path" | xxd -p) && code --folder-uri "vscode-remote://dev-container+${p//[[:space:]]/}/src/astrobee/src") -``` +Start VS Code, run the `Dev Containers: Open Folder in Container...` command from the Command Palette (F1); Or you can open the `$ASTROBEE_WS/src` folder through the VSCode graphical interface, and you should then see a popup dialog from the Dev Containers plugin. Click the "Reopen in Container" button. -Or you can open the `$ASTROBEE_WS/src` folder through the VSCode graphical interface, and you should then see a popup dialog from the Dev Containers plugin. Click the "Reopen in Container" button. +You can choose between the `local` and `remote` profile. The `remote` profile is designed to run on remote servers and it is configured to open a vnc server and broadcast it in port 5900. -Either way, the Dev Containers plugin will download a pre-built ARS Docker image from our official repository, start it running, and provide you with a development environment running inside the container. +After the devcontainer has started, if you continue using `DISPLAY=:0` (default), it will open the graphical application on the vnc server, if you set `DISPLAY=:1` in the terminal with `export DISPLAY=:1`, it will forward using X11 (you can switch back to `:0` for vnc). +To open the vnc viewer in your local: + +```bash +sudo apt-get install xtightvncviewer +vncviewer localhost::5900 -encodings "copyrect tight hextile zlib corre rre raw" +``` You can manage your Dev Containers configuration using the files in the `.devcontainer` folder at the top level. For example, you can select a different Docker image to install from [the list on GitHub](https://github.com/nasa/astrobee/pkgs/container/astrobee) using the `FROM` command in the `Dockerfile`. @@ -48,7 +49,7 @@ You can manage your Dev Containers configuration using the files in the `.devcon You can start by selecting `View->Terminal` in the VSCode graphical interface. This will display a terminal session inside the Docker container where you can run arbitrary commands. Your container will persist throughout your VSCode session, and changes you make using the VSCode editor will be reflected inside the container, making it easy to do quick interactive edit/build/test cycles. -## Enable x-forwarding from the Dev Container +## Enable x-forwarding from the Dev Container (local) In a cmd line in your host environment (not in the docker container) run: ```bash @@ -62,14 +63,6 @@ This runs inside the Docker container: ```bash catkin build -catkin build --make-args tests -catkin build --make-args test -source devel/setup.bash -catkin_test_results build -``` - -For testing, you can alternatively use the script to produces better debug output if there is a failed test: -```bash ./scripts/run_tests.sh ``` @@ -110,6 +103,8 @@ The `run.sh` script (optionally downloads and) runs ARS Docker images. The two scripts have similar options to make it easy to run the specific image you just built. +If you want to run the docker containers directly on remote servers (with no display), there are methods to do this via VNC in \subpage vnc-docker or X11 in \subpage ssh-docker + # Building Docker images ## Build stages diff --git a/scripts/start_vnc.sh b/scripts/start_vnc.sh new file mode 100755 index 0000000000..39ea1d72de --- /dev/null +++ b/scripts/start_vnc.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# This script is designed to be run inside the container (Dockerfile "CMD") to start up the necessary daemons. + +export DISPLAY=${DISPLAY:-:0} # Select screen 0 by default. +x11vnc -bg -forever -nopw -quiet -display WAIT$DISPLAY & +Xvfb $DISPLAY -screen 0 1024x768x16 & +sleep 1 + +xdpyinfo + +# disable screen saver and power management +xset -dpms & +xset s noblank & +xset s off & + +# start window manager +/usr/bin/startxfce4 --replace > $HOME/wm.log & + +# CMD script should not exit +sleep infinity