Difference between revisions of "VS Code Remote Development"

From UFRC
Jump to navigation Jump to search
 
(42 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
This repo provides information on running VSCode Server on HiPerGator, including running Jupyter notebooks. While I work with Research Computing, and this may eventually be transitioned to our official documentation, **this is currently not officially supported by UF Research Computing.**
+
This guide provides information on running VS Code Remote Development on HiPerGator, including running Jupyter notebooks. This has been updated in December 2022 when Microsoft [https://code.visualstudio.com/blogs/2022/12/07/remote-even-better integrated Remote Development into VS Code].
  
 +
==Introduction==
 
Why might you want to do this?
 
Why might you want to do this?
  
* VSCode is a nice IDE with many great features, including [GitHub Copilot](https://github.com/features/copilot) (which most UF users should be able to access for free--via either student or faculty/staff [GitHub Education](https://education.github.com/) plans).
+
* VS Code is a nice IDE with many great features, including [https://github.com/features/copilot GitHub Copilot] (which most UF users should be able to access for free--via either student or faculty/staff [https://education.github.com/ GitHub Education] plans).
* [HiPerGator](https://www.rc.ufl.edu/get-started/hipergator/) provides a powerful compute environment with thousands of cores, petabytes of storage, and powerful GPUs.
+
* [https://www.rc.ufl.edu/get-started/hipergator/ HiPerGator] provides a powerful compute environment with thousands of cores, petabytes of storage, and powerful GPUs.
* But, combining the two can be problematic...
+
* Things to consider:
  * Remote SSH setup is complicated by MFA and the need to tunnel into a compute server with your running job. This can be worked out, but is a bit cumbersome.
+
** '''The use of [https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh vscode remote ssh] extension is discouraged as you can accidentally end up running scripts on the login servers and have your account suspended. See [[VSCode Remote Development]] for details.
  * You can accidentally end up running scripts on the login servers and have your account suspended.
+
** Even if you tunnel into the server running your job, your VSCode session is outside of the resources assigned to your job, and your account may be suspended.
  * Running VSCode on HiPerGator through OOD is kind of slow and limiting in terms of extensions and updates.
+
** Running VS Code on HiPerGator through OOD is kind of slow and limiting as vscode environment module updates can lag behind the rapid vscode release schedule.
* With VSCode Server (currently in [private beta](https://code.visualstudio.com/blogs/2022/07/07/vscode-server), 2022-10-07), you can startup the server within an interactive job with whatever resources you have requested and connect to it in your web browser. No MFA issues, install your desired extensions, connect to GitHub Copilot, run and debug your code easily!
+
* With VS Code Remote Development, you can startup the server within an interactive job with whatever resources you have requested and connect to it in your web browser from [https://vscode.dev/ https://vscode.dev/]. There are no MFA issues, and you can install your desired extensions, connect to GitHub Copilot, and run and debug your code easily!
  
== Request access to the VSCode Server private beta ==
+
==VSCode Setup==
 +
===Using hpg env module===
 +
If you don't mind staying on Research Computing's update schedule, you can put the following commands into the job script that starts the vscode server and the tunnel in a SLURM job:
  
As of this writing, VSCode Server is still in private beta. This means that you will need to request access. See: [https://code.visualstudio.com/blogs/2022/07/07/vscode-server#_getting-started](https://code.visualstudio.com/blogs/2022/07/07/vscode-server#_getting-started) for the sign-up form.
+
export XDG_RUNTIME_DIR=${SLURM_TMPDIR}
 +
module load vscode
 +
code tunnel
  
== Install VSCode Server in your ~/bin folder ==
+
===Personal VSCode install===
  
The installation instructions for VSCode Server will not quite work as-is on HiPerGator as the script that is used relies on `sudo`, which users do not have.
+
This may become somewhat optional as Research Computing updates VS Code, but this does give you full control over the version to use.
  
The following modifications are needed.
+
If missing ~/bin, create it with
 +
mkdir ~/bin
  
1. Download and keep the `setup.sh` script:
+
# Download the x64 CLI for Linux package from the [https://code.visualstudio.com/#alt-downloads VS Code Downloads site ].
 +
# Transfer the download to HiPerGator.
 +
# Extract the tar.gz file and copy the binary to ~/bin:
  
    ```bash
+
tar -xvf vscode_cli_alpine_x64_cli.tar.gz
    wget https://aka.ms/install-vscode-server/setup.sh
+
cp code ~/bin/
    ```
 
  
1. Edit the `setup.sh` script:
+
== Test VSCode Tunnel==
  * Change line 3 (You can replace `$USER` with your username, though it should work as-is):
 
  
        ```diff
+
See [https://help.rc.ufl.edu/doc/Development_and_Testing this page for information on development sessions HiPerGator], but something like the following should work:
        - INSTALL_LOCATION=/usr/local/bin/code-server
 
        + INSTALL_LOCATION=/home/$USER/bin/code-server
 
      ```
 
  
  * Delete or comment out lines 58-67 (note line numbers are included here):
+
# <code>srundev</code> and wait for the session to start.
 +
# Start VS Code Server: <code>code tunnel</code>
 +
#* The first run will prompt you to accept license conditions and do some configuration which is important to do in an interactive session.
 +
# Use ''''Ctrl-C'''' key combination to stop the <code>tunnel</code> process.
 +
# Exit the srun session: <code>exit</code>
  
        ```diff
+
== Regular Use ==
        - 58  if command_exists sudo;
 
        - 59  then
 
        - 60    if [ "$DOWNLOAD_WITH" = curl ]; then
 
        - 61      sudo curl -sSL "$INSTALL_URL" -o "$INSTALL_LOCATION"
 
        - 62    else
 
        - 63      sudo wget -qO "$INSTALL_LOCATION" "$INSTALL_URL"
 
        - 64    fi
 
        - 65
 
        - 66    sudo chown $USER $INSTALL_LOCATION
 
        - 67  else
 
        ```
 
  
  * Delete or comment out line 73:
+
Now that VS Code is set up, it should be relatively easy to start. You can either submit a job or run in an interactive session. In general job submission is more robust and the favored method.
  
        ```diff
+
=== Submit a job ===
        - 73  fi
 
        ```
 
  
1. Run the edited `setup.sh`, which will download and install `code-server` at `~/bin/code-server`, which is in your `$PATH`.
+
* Log into HiPerGator
 +
* Submit a tunnel job.  
 +
** See the example scripts below.  
 +
** Be sure to adjust the resource requests as needed for your analysis.
 +
** Use <code>sbatch</code> to submit the job script: e.g. <code>sbatch tunnel.sh</code>
 +
** Once the job starts, connect to your remote server. Check the log file for details.
  
== First run: Launch a development session and start VSCode Server ==
+
==== CPU only job script example ====
 +
<pre>
 +
#!/bin/bash
 +
#SBATCH --job-name=vscode
 +
#SBATCH --nodes=1
 +
#SBATCH --ntasks=1
 +
#SBATCH --cpus-per-task=2
 +
#SBATCH --mem=8gb
 +
#SBATCH --time=08:00:00 # example 8 hrs
  
1. See [this page for information on development sessions HiPerGator](Development_and_Testing), but something like this should work: `srun --mem=4gb --time=01:00:00 --pty bash -i`
+
hostname;date;pwd
 +
export XDG_RUNTIME_DIR=${SLURM_TMPDIR}
  
2. Start VSCode Server: `code-server`
+
# HPG install of vscode. Comment the next line out with '#' if using a personal install
 +
module load vscode.
  
3. Continue to follow steps 2-5 on the [VSCode Server page](https://code.visualstudio.com/blogs/2022/07/07/vscode-server#_getting-started) to authenticate your GitHub account, name your server (HiPerGator might be a good name), and accept terms.
+
# For either the HPG or personal install of vscode
 +
code tunnel
 +
</pre>
  
4. You are mostly set! Though you can add additional extensions, like GitHub Copilot, if you want.
+
==== GPU job script example ====
 +
<pre>
 +
#!/bin/bash
 +
#SBATCH --job-name=vscode
 +
#SBATCH --partition=gpu
 +
#SBATCH --gpus=a100:1
 +
#SBATCH --nodes=1
 +
#SBATCH --ntasks=1
 +
#SBATCH --cpus-per-task=2
 +
#SBATCH --mem=8gb
 +
#SBATCH --time=08:00:00 # example 8 hrs
  
== For daily use ==
+
hostname;date;pwd
 +
export XDG_RUNTIME_DIR=${SLURM_TMPDIR}
  
Now that VSCode Server is setup, it should be relatively easy to start. For the most part, the process is:
+
# HPG install of vscode. Comment the next line out with '#' if using a personal install
 +
module load vscode.
  
1. Log into HiPerGator
+
# For either the HPG or personal install of vscode
 +
code tunnel
 +
</pre>
  
2. Start a development session, [requesting GPUs if needed](https://help.rc.ufl.edu/doc/GPU_Access#Interactive_Access), and other resources for the time you want to work.
 
  
3. For Jupyter notebooks it is important to:
 
  
* Load Jupyter and the module you need for the kernel you want to use, e.g. for Tensorflow: `module load jupyter tensorflow/2.7.0`
+
=== For an interactive method ===
* Export the `XDG_RUNTIME_DIR` to set temp directory (otherwise it tries to use `/run/user/`, which you can't be written to!): `export XDG_RUNTIME_DIR=${SLURM_TMPDIR}`
+
'''Note: srun sessions will end if your network connection to HPG is broken or if you exit.'''
  
4. Start VSCode server: `code-server`
+
# Start a development session, [https://help.rc.ufl.edu/doc/GPU_Access#Interactive_Access requesting GPUs if needed], and other resources for the time you want to work.
 +
#* For example, for a session requesting 4 cores, 15GB of RAM, an A100 GPU for 1 hour: <code>'''srun -c 4 --mem 15gb -p gpu --gres gpu:a100:1 -t 60 --pty bash -i'''</code>
 +
# For Jupyter notebooks, it is important to
 +
#* Load Jupyter  and the module you need for the kernel you want to use, e.g. for Tensorflow: <code>module load jupyter tensorflow/2.7.0</code>
 +
#* Export the <code>XDG_RUNTIME_DIR</code> to set temp directory (otherwise it tries to use <code>/run/user/</code>, which you can't be written to!): <code>export XDG_RUNTIME_DIR=${SLURM_TMPDIR}</code>
 +
# Start VS Code tunnel: <code>code tunnel</code>
 +
#*This can all be done with this line: <code>'''module load jupyter tensorflow/2.7.0; export XDG_RUNTIME_DIR=${SLURM_TMPDIR}; code tunnel'''</code>
  
This can all be done with this line: `module load jupyter tensorflow/2.7.0; export XDG_RUNTIME_DIR=${SLURM_TMPDIR}; code-server`
+
==Connect To The Tunnel==
   
+
* Find the authentication information. Look at the SLURM job log file e.g. with 'less slurm-JOBID.out'. At the top you will see text similar to the following example
5. Connect to the URL provided in your browser.
+
<pre>
 +
* Visual Studio Code Server
 +
*
 +
* By using the software, you agree to
 +
* the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and
 +
* the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement).
 +
*
 +
[2024-02-19 16:57:03] info Using Github for authentication, run `code tunnel user login --provider <provider>` option to change this.
 +
To grant access to the server, please log into https://github.com/login/device and use code 14AJ-AYFD
 +
[2024-02-19 17:08:11] info Creating tunnel with the name: c0700a-s4ufhpc
  
6. Code away!
+
Open this link in your browser https://vscode.dev/tunnel/c0700a-s4ufhpc
 +
</pre>
 +
 
 +
* Go either to the link shown in the above example
 +
or go to [https://vscode.dev/ https://vscode.dev/] and click on the 'Connect to tunnel' button.
 +
* Authenticate with your GitHub account using the above code.
 +
* Connect to the URL provided in your browser.
 +
* Once you open VS Code in the browser, open the command palette (ctrl+shift+p) and select the appropriate Jupyter Interpreter. 
 +
* Code away!

Latest revision as of 20:43, 13 November 2024

This guide provides information on running VS Code Remote Development on HiPerGator, including running Jupyter notebooks. This has been updated in December 2022 when Microsoft integrated Remote Development into VS Code.

Introduction

Why might you want to do this?

  • VS Code is a nice IDE with many great features, including GitHub Copilot (which most UF users should be able to access for free--via either student or faculty/staff GitHub Education plans).
  • HiPerGator provides a powerful compute environment with thousands of cores, petabytes of storage, and powerful GPUs.
  • Things to consider:
    • The use of vscode remote ssh extension is discouraged as you can accidentally end up running scripts on the login servers and have your account suspended. See VSCode Remote Development for details.
    • Even if you tunnel into the server running your job, your VSCode session is outside of the resources assigned to your job, and your account may be suspended.
    • Running VS Code on HiPerGator through OOD is kind of slow and limiting as vscode environment module updates can lag behind the rapid vscode release schedule.
  • With VS Code Remote Development, you can startup the server within an interactive job with whatever resources you have requested and connect to it in your web browser from https://vscode.dev/. There are no MFA issues, and you can install your desired extensions, connect to GitHub Copilot, and run and debug your code easily!

VSCode Setup

Using hpg env module

If you don't mind staying on Research Computing's update schedule, you can put the following commands into the job script that starts the vscode server and the tunnel in a SLURM job:

export XDG_RUNTIME_DIR=${SLURM_TMPDIR}
module load vscode
code tunnel

Personal VSCode install

This may become somewhat optional as Research Computing updates VS Code, but this does give you full control over the version to use.

If missing ~/bin, create it with

mkdir ~/bin
  1. Download the x64 CLI for Linux package from the VS Code Downloads site .
  2. Transfer the download to HiPerGator.
  3. Extract the tar.gz file and copy the binary to ~/bin:
tar -xvf vscode_cli_alpine_x64_cli.tar.gz
cp code ~/bin/

Test VSCode Tunnel

See this page for information on development sessions HiPerGator, but something like the following should work:

  1. srundev and wait for the session to start.
  2. Start VS Code Server: code tunnel
    • The first run will prompt you to accept license conditions and do some configuration which is important to do in an interactive session.
  3. Use 'Ctrl-C' key combination to stop the tunnel process.
  4. Exit the srun session: exit

Regular Use

Now that VS Code is set up, it should be relatively easy to start. You can either submit a job or run in an interactive session. In general job submission is more robust and the favored method.

Submit a job

  • Log into HiPerGator
  • Submit a tunnel job.
    • See the example scripts below.
    • Be sure to adjust the resource requests as needed for your analysis.
    • Use sbatch to submit the job script: e.g. sbatch tunnel.sh
    • Once the job starts, connect to your remote server. Check the log file for details.

CPU only job script example

#!/bin/bash
#SBATCH --job-name=vscode
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=2
#SBATCH --mem=8gb
#SBATCH --time=08:00:00 # example 8 hrs

hostname;date;pwd
export XDG_RUNTIME_DIR=${SLURM_TMPDIR}

# HPG install of vscode. Comment the next line out with '#' if using a personal install
module load vscode.

# For either the HPG or personal install of vscode
code tunnel

GPU job script example

#!/bin/bash
#SBATCH --job-name=vscode
#SBATCH --partition=gpu
#SBATCH --gpus=a100:1
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=2
#SBATCH --mem=8gb
#SBATCH --time=08:00:00 # example 8 hrs

hostname;date;pwd
export XDG_RUNTIME_DIR=${SLURM_TMPDIR}

# HPG install of vscode. Comment the next line out with '#' if using a personal install
module load vscode.

# For either the HPG or personal install of vscode
code tunnel


For an interactive method

Note: srun sessions will end if your network connection to HPG is broken or if you exit.

  1. Start a development session, requesting GPUs if needed, and other resources for the time you want to work.
    • For example, for a session requesting 4 cores, 15GB of RAM, an A100 GPU for 1 hour: srun -c 4 --mem 15gb -p gpu --gres gpu:a100:1 -t 60 --pty bash -i
  2. For Jupyter notebooks, it is important to
    • Load Jupyter and the module you need for the kernel you want to use, e.g. for Tensorflow: module load jupyter tensorflow/2.7.0
    • Export the XDG_RUNTIME_DIR to set temp directory (otherwise it tries to use /run/user/, which you can't be written to!): export XDG_RUNTIME_DIR=${SLURM_TMPDIR}
  3. Start VS Code tunnel: code tunnel
    • This can all be done with this line: module load jupyter tensorflow/2.7.0; export XDG_RUNTIME_DIR=${SLURM_TMPDIR}; code tunnel

Connect To The Tunnel

  • Find the authentication information. Look at the SLURM job log file e.g. with 'less slurm-JOBID.out'. At the top you will see text similar to the following example
* Visual Studio Code Server
*
* By using the software, you agree to
* the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and
* the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement).
*
[2024-02-19 16:57:03] info Using Github for authentication, run `code tunnel user login --provider <provider>` option to change this.
To grant access to the server, please log into https://github.com/login/device and use code 14AJ-AYFD
[2024-02-19 17:08:11] info Creating tunnel with the name: c0700a-s4ufhpc

Open this link in your browser https://vscode.dev/tunnel/c0700a-s4ufhpc
  • Go either to the link shown in the above example

or go to https://vscode.dev/ and click on the 'Connect to tunnel' button.

  • Authenticate with your GitHub account using the above code.
  • Connect to the URL provided in your browser.
  • Once you open VS Code in the browser, open the command palette (ctrl+shift+p) and select the appropriate Jupyter Interpreter.
  • Code away!