Skip to content

Commit

Permalink
Remote docker vscode (#779)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
marinagmoreira and trey0 authored Jul 31, 2024
1 parent c1d2d76 commit 101c0a8
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 21 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
],
"workspaceMount": "source=${localWorkspaceFolder},target=/src/astrobee/src,type=bind",
"workspaceFolder": "/src/astrobee/src"
}
}
31 changes: 31 additions & 0 deletions .devcontainer/remote/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions .devcontainer/remote/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions doc/documentation_local.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv=Refresh content="0;url=html/index.html"></head></html>
33 changes: 14 additions & 19 deletions scripts/docker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -31,24 +29,27 @@ 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`.

## Interactively develop inside the Docker container

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
Expand All @@ -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
```

Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions scripts/start_vnc.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 101c0a8

Please sign in to comment.