Search code examples
visual-studio-codevscode-remote

How can I ensure VS Code Remote SSH server runs on a compute node of our cluster?


I would like to use VS Code Remote SSH to do development work on our institution's cluster. Our cluster uses an architecture with a login node that receives all SSH requests. We are discouraged from using the login node for any tasks that take longer than a few seconds to avoid denial of service. To perform terminal commands that might take some time, we can use a command to spawn an interactive job on a compute node. The terminal takes us to that node automatically once the interactive job is running.

My issue is that the VS Code server on the host gets set up on the login node, and any tasks involving file manipulation, processing, etc., run on the login node. I do not see any way to inject a command to spawn an interactive job before the VS Code server is set up on the host. I also do not see a way to manually set up the server on a compute node and then connect to it.

So far, I have successfully modified .bashrc server side, and the terminal.integrated.env.linux and terminal.integrated.shellArgs.linux settings in VS Code locally, to automate the above process for new terminals spawned in the "Terminal" menu. If I create a new terminal once connected, things work as I expect via that terminal. This does not appear to change the initial SSH connection or server setup.

How can I get the VS Code server to run on a compute node? Or alternately ensure that these various tasks run on compute nodes?

Edit: I forgot about this question. Good news though, an issue on Github about this has made it to the backlog for future implementation.


Solution

  • After 3.5 years, I finally have an answer to this question!

    The VSCode Remote team has developed Remote Tunnels, which forms a secured, tunneled connection between a remote machine and local VSCode (or in the browser). This requires a GitHub account.

    To use this with a cluster environment:

    1. Go to the link above and install VSCode CLI in your user space on the cluster. I recommend adding the install folder to $PATH.

    2. Start a batch job with the command code tunnel as the payload. This is a blocking command, so it should keep the job from terminating.

    3. Check the stdout output file, produced by the job, for an 8-digit activation code.

    4. Use the activation code as instructed by code tunnel.

    5. Open VSCode wherever you like, and use either the command palette or the bottom-left VSCode Remote icon/button (looks like ><) to connect to a tunnel.

    6. Find the tunnel with the name you gave, and connect.

    From here, everything works more or less like Remote SSH. You can make multiple VSCode instances connect to the same tunnel.

    I like to do this with an interactive desktop job (via Open OnDemand) for a little more control in case things go wrong. Then I can terminate the tunnel server and restart it, and reconnecting is easy as I dont need to enter the code a second time.