Using VS Code on the Cluster

Table of Contents

Introduction

Microsoft's Visual Studio Code (aka VS Code) is a popular source code editor and development environment with support for many different programming languages.  VS Code software includes a tool called VS Code Server that acts as a gateway from the VS Code session on your computer to the cluster so you execute your code on the cluster from within your VS Code session.

Below, we will demonstrate two methods for connecting to VS Code Server and launching jobs on the clusters.  SSH access to nova-vscode will no longer be available.

  1. Using the new VScode Tunnel App
  2. Running VS Code from Open OnDemand

Using the new VSCode Tunnel App

The new VSCode tunnel app allows users to tunnel to compute nodes instead of nova-vscode.  This helps share resources and makes what's available more aligned with the users needs. 

First in Open OnDemand select VSCode Tunnel

Start a new VSCode instance with your needed resources as parameters.  Wait until the session says it's running.  After that you'll be given directions for how to authenticate your device:

Device Authentication

You'll need to enter the device code in bullet three into Microsoft's device login page.  You'll be asked to use your ISU account to authenticate and to give VS Code the necessary permissions. After this open VSCode on your personal computer and go to "Remote Explorer":
Remote Explorer

There you can connect to your compute node endpoint.  

If you are using github or any repository with pubkeys you will need to add the cluster.pub key from your  /home/<your netid>/.ssh/ folder to your identity.  Tunnels have no way of forwarding ssh keys from your local agent to the remote machine.

 

Return to Top of Page

Running VS Code from Open OnDemand

  1. Go to https://nova-ondemand.its.iastate.edu/ and log in.
  2. From the Interactive Apps menu at the top select “VS Code Server”
    Nova OnDemand Home page
  3. Select the interactive partition, as well as any other desired options (the defaults are usually sufficient) and click “Launch”
  4. A new VS Code session will automatically be created on one of the Nova compute nodes. This may take a few minutes depending on cluster demand. Once the session has been created, click “Connect to VS Code”.
    VS Code Server details
  5. Create a symbolic link to store extensions. This only needs to be done the first time you run VS Code OnDemand.
    1. Open the terminal window by going to File->View->Terminal
    2. In the terminal type the following commands, replacing <GroupName> with your group name and <UserName> with your user name.
      1. Create a folder in work for the VSCode extensions:
        mkdir -p /work/<GroupName>/<UserName>/.local/share/code-server
      2. Move any existing extension files to the new directory:
        mv ~/.local/share/code-server/ /work/<GroupName>/<UserName>/.local/share
      3. Create a symbolic link between the old extensions directory and the new one:
        ln -s /work/<GroupName>/<UserName>/.local/share/code-server  ~/.local/share/code-server
  6. Install any desired extensions from the Extensions sidebar on the left-hand side. This only needs to be done the first time you run VS Code OnDemand, or whenever you need new extensions.
     Extensions menu in VS Code

Moving Files to and from the Local Machine to VS Code OnDemand

  1. Open the File Explorer sidebar on the left-hand side of VS Code.

    File explorer in VS Code

  2. To Download Files:
    1. Right-click on the file you would like to download from VS Code OnDemand to your local computer and select “Download…” from the menu. The file download will automatically start.
  3. To Upload Files:
    1. Right-click on the folder where you would like to upload the file to and select “Upload…” from the menu.
    2. Select the file on your local computer in the File Upload dialog that appears and then click “Open”

Run a Test Program [Optional] 

  1. This test program is written in Python. To run it, ensure the Python extension is installed. See step 6 of “Using VS Code on Nova OnDemand” if you need instructions for how to do this.
  2. Create a new folder for your test code:
    1. In the Explorer sidebar on the left-hand side right-click and select “New Folder…”
    2. Give the folder a descriptive name, e.g. “vscode_test”
  3. Make the new folder the working folder:
    1. From the menu button on the top left, select File->Open Folder…
    2. In the Command Palette that opens, type in the path to your folder and click “OK”
  4. Create a new Python code file:
    1. From the menu button on the top left, select File->New File…
    2. In the Command Palette that opens, select “Python File”
  5. Add the following test code to your new file:

    import socket
    
    computerName = socket.getfqdn()
    print(“This computer is: “ + computerName)
  6. Save the file:
    1. From the menu button on the top left, select File->Save
    2. In the Command Palette that opens, type the desired file name, e.g. vscode_test.py, and click “OK”
  7. To run the code, click the green play button in the top right.
     run-code-press-green-play-button
  8. The VS Code terminal will open if it wasn’t already and show the code output. The code output should read something similar to:
    This computer is: nova18-71
    1. The computer name will change based on which compute node you are connected to.
    2. If the computer name is “nova.its.iastate.edu” you have done something wrong! You should never run code on the Nova head node as it will result in poor performance.

Troubleshooting

The VS Code OnDemand Window Stopped Responding.

  • Most likely your OnDemand session timed out. Return to the Nova OnDemand webpage and request a new session.
  • If your session hasn’t timed out, the server may be time slicing (i.e. pausing your session to let other small jobs through). To prevent this, make sure you request the interactive partition when creating your OnDemand session.

Unable to Access the Nova OnDemand Webpage.

  • Make sure you are connected to the Iowa State University network either on campus, or via the Iowa State VPN.

An Extension Isn’t Listed on VS Code OnDemand

  • Due to licensing issues, the official Microsoft VS Code extensions marketplace isn’t available in VS Code OnDemand and it instead uses the Open-VSX extensions gallery. While most of the popular extensions are available in Open-VSX, some are not. To manually install an extension from the Microsoft VS Code extensions marketplace:
    1. Go to the website for the extension and select Download Extension->Linux x64
    2. Copy the file to one of the directories shared on Nova (e.g. your home or work directory).
    3. Open the terminal window in VS Code and send the following command (where you replace <Path> with the full path location of the vsix file downloaded for the extension): 
      code-server --install-extension <Path>

Return to Top of Page