Search code examples
visual-studio-codecluster-computingremote-debugging

How to get VS Code Server working in RHEL9?


I would like to use the remote development capabilities of VS Code in the context of an LSF compute cluster (but I think the same question would be relevant on e.g. a Slurm cluster). In particular, I would like to launch the VS Code Server (https://code.visualstudio.com/docs/remote/vscode-server) on a worker node, and then connect to it from my desktop computer. I can't do this using the usual VS Code remote development workflow because the worker nodes do not run an ssh server. (Ok, they do, but we're not supposed to use it because it messes up the cluster resource allocation system.)

In order to get an interactive shell session on a worker node, while sitting at my desktop (Ubuntu) machine, I do:

ssh login1   # login1 is the name of the cluster login node
bsub -Is -n 4 /bin/bash  # Requests an interactive bash session on a worker node, using 4 CPUs

At that point, I have an interactive bash session running on the worker node. I would like to launch VS Code Server on this worker node, and then connect to VS Code Server from plain-old VS Code running on my desktop machine.

I have tried

code tunnel

on the worker machine. It responds with

spawn <path to VS Code install directory>/bin/code-tunnel ENOENT

and then seemingly exits. ps -ef | grep <my username> does not reveal any processes running afterwards that were not running beforehand. Running code tunnel --verbose does the same thing.

The cluster worker nodes run Oracle Linux 9, which I believe is bug-for-bug compatible with RHEL 9. In particular, cat /etc/os-release yields:

NAME="Oracle Linux Server"
VERSION="9.2"
<et cetera>

I am using VS Code version 1.81.1 on the worker node. code --version yields:

1.81.1
6c3e3dba23e8fadc360aed75ce363ba185c49794
x64

I installed it under my home directory as my normal user account using the .tar.gz link for Linux provided here: https://code.visualstudio.com/Download

Has anyone gotten this to work in a cluster environment?


Solution

  • Here's what worked for me:

    1. Obviously, install VS Code on your desktop machine.

    2. Download the VS Code CLI for Linux from this page (https://code.visualstudio.com/Download), and somehow get it to your home dir. It will be a .tar.gz file named vscode_cli_alpine_x64_cli.tar.gz. You must get the one labelled "CLI", not the regular Linux .tar.gz file. (see illustration below)

    Image showing exactly where to click

    1. ssh into a submit node, cd to wherever you saved vscode_cli_alpine_x64_cli.tar.gz, and do
    tar xvf vscode_cli_alpine_x64_cli.tar.gz
    

    This will produce a single (executable) file, named code. Confusingly, this is not the same as the plain-old VS Code executable, which is also named code on Linux.

    1. Do mv code code-cli to rename the just-downloaded executable, to not go insane.

    2. Do bsub -Is -n 4 /bin/bash to get an interactive session on a worker node.

    3. cd to wherever you left code-cli and do ./code-cli tunnel. Follow the instructions it gives you. You will have to login to your GitHub account, and do various other things. You will have to supply a name for your "tunnel". I called mine "worker". Eventually GitHub will have a tunnel named "worker" defined.

    4. Launch VS Code on your desktop machine. Click the bottom-left "><" button to open a remote window, select "Connect to Tunnel...", wait a bit, then select the the tunnel you created in step 5. You should now be connected to a remote session running on the worker node.

    I think you probably will have to repeat step 5 for every novel worker node bsub assigns you to, but I'm not sure about that part...

    It's maybe also worth mentioning that I've basically given up on this method and gone back to using bsub -XF to enable plain old X11 forwarding from the worker node. The method described above is just too much hassle.