Skip to content

Commit d308993

Browse files
authored
Merge pull request #391 from SouthernMethodistUniversity/update_vscode_instructions
Update vscode instructions
2 parents 9ee40b0 + 5763d09 commit d308993

5 files changed

Lines changed: 276 additions & 5 deletions

File tree

docs/applications/vscode.md

Lines changed: 276 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
33
Visual Studio Code is a popular code editor with extensions for coding
44
in different languages. We recommend using Visual Studio Code through the
55
[HPC OnDemand Web Portal](https://hpc.m3.smu.edu/). See instructions
6-
for the using the [portal version](/applications/vscode.md#portal) below.
6+
for the using the [portal version (preferred)](/applications/vscode.md#portal) below.
7+
You can also use [Remote Tunnels](/applications/vscode.md#tunnel) submitted via batch jobs.
8+
9+
```{important}
10+
We understand that research and code development often requires interactive
11+
use. However, interactive use is inherently inefficient and often results
12+
in substantial HPC resources sitting idle. We highly recommend submitting
13+
scripted and batched jobs whenever possible. If you would like assistance
14+
converting an interactive workflow, please [contact us.](about:contact).
15+
```
716

817
## Portal
918

10-
1. Select "Visual Studio Code" from the "Interactive Apps" drop-down menu.
19+
Using the [HPC OnDemand Web Portal](https://hpc.m3.smu.edu/) portal is the
20+
preferred and easiest way to use Visual Studio Code on M3.
21+
22+
1. Select "Visual Studio Code" from the "Interactive Apps" drop-down menu.
1123
2. Select options required for your Visual Studio Code instance. These
1224
options are the same as those requested via a standard Slurm script.
1325
Any modules that are needed at runtime should be loaded using the
@@ -30,14 +42,273 @@ run modules and code with the Slurm scheduler from an SSH session.
3042
Interactive Sessions" tab in your browser and select "Delete" and
3143
"Confirm", when prompted, to cancel the job.
3244

45+
## Tunnel
46+
47+
Visual Studio Code can also be used on M3 or the SuperPOD by starting
48+
a SSH tunnel in a job. The following is the recommended way of starting
49+
a session.
50+
51+
### Setup on your computer
52+
53+
In order to use the remote tunnel, you will need the following:
54+
55+
- A recent version of [VSCode](https://code.visualstudio.com/download).
56+
- Install the following extension (these extensions are all published by Microsoft)
57+
- [Remote Explorer](https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-explorer)
58+
- [Remote - SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh)
59+
- [Remote - Tunnels](https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-server)
60+
61+
### HPC Job Script
62+
63+
On either M3 or the SuperPOD, copy the following job script and make any necessary modifications.
64+
You will need to change the Slurm account to an active allocation in [ColdFront](https://hpcaccess.smu.edu)
65+
that you have access to -- the one in this script is an example and will not run.
66+
You may need to adjust the requested resources to match your needs, for instance, if you need
67+
more cores or memory.
68+
69+
We'll call this file `vscode_tunnel.sbatch`, but you can name it something else if you like.
70+
71+
```bash
72+
#!/bin/bash -e
73+
#SBATCH -J code_tunnel # job name (optional)
74+
#SBATCH -p dev # partition
75+
#SBATCH --time=0-01:00:00 # time in Days-HH:MM:SS
76+
#SBATCH -c 1 # number of cores
77+
#SBATCH --mem=4G # memory in GB
78+
#SBATCH -A peruna_0001 # slurm account to use (MUST CHANGE!)
79+
#SBATCH --signal=B:USR1@15 # send interrupt signal 15s before end
80+
81+
# Set a name for the tunnel. We recommend using something
82+
# that identifies the system, lik m3tunnel on M3 and
83+
# superpodtunnel on the SuperPOD
84+
TUNNEL_NAME="m3tunnel"
85+
86+
#########################################################
87+
# You shouldn't need to change anything below here. #
88+
#########################################################
89+
90+
# Function executed when signal USR1 is sent
91+
# before the job ends to clean up running processes
92+
function sig_handler()
93+
{
94+
echo "function sig_handler called"
95+
echo "Signal trapped - `date`"
96+
97+
# stop any running commands
98+
# Check if the AUTH PID exists
99+
if [[ -v AUTH_PID ]]; then
100+
# Check if the auth process is running
101+
if ps -p "$AUTH_PID" >/dev/null; then
102+
# kill it, the -15 tries to kill "nicely"
103+
kill -15 $AUTH_PID
104+
fi
105+
fi
106+
107+
# check if the TUNNEL PID exists
108+
if [[ -v TUNNEL_PID ]]; then
109+
# Check if the auth process is running
110+
if ps -p "$TUNNEL_PID" >/dev/null; then
111+
# kill it, the -15 tries to kill "nicely"
112+
kill -15 $TUNNEL_PID
113+
fi
114+
fi
115+
116+
# delete the temporary folder if it exists
117+
if [[ -v JOBTEMP ]]; then
118+
if [ -d "$JOBTEMPR" ]; then
119+
rm -rf $JOBTEMP
120+
fi
121+
fi
122+
123+
exit 0
124+
}
125+
126+
# "trap" or wait for the signal USR1 and call the sig_handler
127+
# helper function to clean up temporary files and running
128+
# processes
129+
trap 'sig_handler' SIGUSR1
130+
131+
# create a temp directory in $SCRATCH to download VSCode
132+
# cli tools and run out of
133+
# Reminder $SCRATCH has a 60 purge policy -- files
134+
# older than 60 days may be permanently deleted without warning
135+
# This will only be used for temporary files and this script
136+
# will try to delete them before the job ends
137+
JOBTEMP=$(TMPDIR=$SCRATCH mktemp -d)
138+
139+
# Download the latest stable version of VSCode CLI tools
140+
# and extract it to the JOBTEMP folder
141+
echo "Downloading VSCode CLI to: ${JOBTEMP}"
142+
curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' | tar -C $JOBTEMP -xzf -
143+
144+
# Generate a login code for the tunnel using Microsoft as the authenticator
145+
echo "Generating authentication code"
146+
VSCODE_CLI_DISABLE_KEYCHAIN_ENCRYPT=1 $JOBTEMP/code tunnel user login --provider microsoft &
147+
148+
# get PID of login code process
149+
AUTH_PID=$!
150+
151+
# wait for authentication to succeed
152+
wait ${AUTH_PID}
153+
154+
# Start the tunnel
155+
# By running this, you are accepting VSCode's license. We highly recommend
156+
# reviewing the license first: https://code.visualstudio.com/license
157+
echo "Starting code tunnel"
158+
$JOBTEMP/code tunnel --accept-server-license-terms --name ${TUNNEL_NAME} &
159+
160+
# Get PID of code tunnel
161+
TUNNEL_PID=$!
162+
163+
# Keep running until we get the interrupt signal or the code server
164+
# session ends
165+
echo "Running"
166+
wait ${TUNNEL_PID}
167+
```
168+
169+
### Submitting the job script
170+
171+
To submit the job script, call
172+
173+
```bash
174+
sbatch vscode_tunnel.sbatch
175+
```
176+
177+
from a login node. You can use the [web portal terminal](https://hpc.m3.smu.edu/pun/sys/shell/ssh/129.119.70.4)
178+
to submit to M3 or you can use SSH session (the SuperPOD is only available via SSH).
179+
180+
Once you submit the job script, you should see something like:
181+
182+
```bash
183+
Submitted batch job 22880401
184+
```
185+
186+
and you can monitor when the job starts or it's state in the queue with
187+
188+
```bash
189+
squeue --me
190+
```
191+
192+
In the `NODELIST(REASON)` column, the reasons `Priority`, `BeginTime`, or `Resources` are
193+
normal and mean your job is waiting for its turn to start. If you see other reasons it may
194+
indicate a issue with the job. The codes are described in the
195+
[Slurm documentation](https://slurm.schedmd.com/job_reason_codes.html) or you can
196+
[contact us](about:contact) with questions about the status.
197+
198+
The amount of time a job takes to start is dependent on how busy the system currently is.
199+
Estimated start times are sometimes available with
200+
201+
```bash
202+
squeue --me --start
203+
```
204+
205+
Estimated start times are based on job requests currently running or waiting in the queue.
206+
If a start time is given, jobs typically (but not always) start before that time.
207+
If the estimate is NA, the start time was not estimated -- the job scheduler does only
208+
computes estimates for a limited number of jobs at a time, so this is not unusual.
209+
210+
Once the job starts, the output of `squeue --me` will look like:
211+
212+
```bash
213+
22880401 dev code_tun peruna R 0:19 1 c031
214+
```
215+
216+
In this case, this tells us the job has been running for 19 seconds on node `c031`.
217+
If you would like the system to email you when the job starts, you can include the
218+
following at the top of the job script before you submit (email will only be sent
219+
to SMU email addresses.)
220+
221+
```bash
222+
#SBATCH --mail-type=BEGIN
223+
#SBATCH --mail-user=peruna@smu.edu
224+
```
225+
226+
### Connecting credentials
227+
228+
Once your job starts, it should generate an output file with a name like
229+
`slurm-22880401.out`. The number will change each time you run and is the
230+
job id that was printed out when you submitted the job script.
231+
232+
From a terminal, you can print out the file with `cat slurm-22880401.out` and
233+
it should look something like (it may need to run for a minute or so before
234+
this is available):
235+
236+
```
237+
Downloading VSCode CLI to: /lustre/scratch/client/users/peruna/tmp.0El3JhwWWT
238+
% Total % Received % Xferd Average Speed Time Time Time Current
239+
Dload Upload Total Spent Left Speed
240+
100 162 100 162 0 0 507 0 --:--:-- --:--:-- --:--:-- 507
241+
100 9816k 100 9816k 0 0 5866k 0 0:00:01 0:00:01 --:--:-- 7580k
242+
Generating authentication code
243+
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code FE71YRZUVM to authenticate.
244+
```
245+
246+
In your web browser, go navigate to [https://microsoft.com/devicelogin](https://microsoft.com/devicelogin) and
247+
enter the code in the log file (in this example `FE71YRZUVM`). You should treat this code like a password.
248+
Sharing it is a violation of [SMU policy](https://www.smu.edu/policy/8-information-technology/8-1-acceptable-use).
249+
250+
![add code to Microsoft allow access page](../images/vscode/add_auth_code.png)
251+
252+
After clicking next on the page, you will be asked to login to a Microsoft account.
253+
We recommend using your SMU account.
254+
255+
After the access code has been added to a Microsoft account, the job script will progress and should
256+
look similar to:
257+
258+
```
259+
Downloading VSCode CLI to: /lustre/scratch/client/users/peruna/tmp.0El3JhwWWT
260+
% Total % Received % Xferd Average Speed Time Time Time Current
261+
Dload Upload Total Spent Left Speed
262+
100 162 100 162 0 0 507 0 --:--:-- --:--:-- --:--:-- 507
263+
100 9816k 100 9816k 0 0 5866k 0 0:00:01 0:00:01 --:--:-- 7580k
264+
Generating authentication code
265+
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code FE71YRZUVM to authenticate.
266+
Starting code tunnel
267+
Running
268+
*
269+
* Visual Studio Code Server
270+
*
271+
* By using the software, you agree to
272+
* the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and
273+
* the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement).
274+
*
275+
276+
Open this link in your browser https://vscode.dev/tunnel/m3tunnel
277+
```
278+
279+
### Connect VSCode to the Tunnel
280+
281+
To connect your VSCode client, click on `Open Remote Window` in the bottom left corner
282+
of VSCode (it is an icon that looks similar to `><`.) That will open up options:
283+
284+
![options presented by VSCode after clicking open remote window.](../images/vscode/options.png)
285+
286+
Select the `Connect to Tunnel` option. Then select the `Microsoft Account` option:
287+
288+
![options to select the type of account used for authorization. Typically this shows Microsoft and Github.](../images/vscode/auth_option.png)
289+
290+
After selecting the `Microsoft Account` type, you may be prompted to login to your Microsoft account.
291+
Then you should be able to select the tunnel you created.
292+
293+
![Shows m3tunnel running on c031 is Online as an option to connect to.](../images/vscode/tunnel.png)
294+
295+
The tunnel name should match the name in the job script (`m3tunnel` in this example), the node it is running on
296+
(`c031` in this example) and it should show as `Online` (sometimes it takes a while for this status to update, so
297+
it is ok if the job is running and it says `Offline`.)
298+
299+
The first time you connect to a tunnel, VSCode may install some components that allows it to connect to
300+
M3 or the SuperPOD. This can can 5-10 minutes, but should only be necessary the first time you connect or
301+
when VSCode has updates.
302+
33303
## SSH on Login Nodes
34304

35305
```{warning}
36306
As a reminder, running code on login nodes is prohibited. This method
37307
is intended only for code editing. If you want to execute code from
38-
Visual Studio Code, please use the [portal version](/applications/vscode.md#portal).
308+
Visual Studio Code, please use the [portal version](/applications/vscode.md#portal)
309+
or [Remote Tunnels](/applications/vscode.md#tunnel).
39310
```
40311

41-
To connect via SSH to a login node, follow the
312+
To connect via SSH to a login node, follow the
42313
[Remove Development using SSH](https://code.visualstudio.com/docs/remote/ssh) instructions
43-
for using the Remote-SSH feature.
314+
for using the Remote-SSH feature.
73 KB
Loading

docs/images/vscode/auth_option.png

27.9 KB
Loading

docs/images/vscode/options.png

116 KB
Loading

docs/images/vscode/tunnel.png

23.1 KB
Loading

0 commit comments

Comments
 (0)