Skip to content

Commit 0146e54

Browse files
abhinavclemsoncopybara-github
authored andcommitted
Add support for vscode and gcs for sps environments.
PiperOrigin-RevId: 934528376
1 parent b38992d commit 0146e54

3 files changed

Lines changed: 408 additions & 24 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# jupyter_setup.sh
3+
4+
# Update and install dependencies
5+
sudo apt update > /dev/null
6+
pip3 install jupyterlab > /dev/null
7+
8+
# Launch Jupyter Lab
9+
# We use {PORT} as a placeholder to be replaced by Python
10+
echo "Starting Jupyter Lab on port {PORT}..."
11+
jupyter lab --allow-root --ip=127.0.0.1 --port={PORT}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# Variables
3+
PORT="{PORT}"
4+
BUCKET_NAME="{BUCKET}"
5+
POD_PATTERN="{WORKLOAD}"
6+
7+
# Paths
8+
WORKSPACE_DIR="$HOME/vscode_workspace"
9+
mkdir -p "$WORKSPACE_DIR"
10+
11+
# 1. Install Dependencies
12+
echo "Step 1: Installing dependencies..."
13+
sudo apt-get update -qq >/dev/null
14+
sudo apt-get install -y -qq inotify-tools curl >/dev/null
15+
16+
if ! command -v code-server &> /dev/null; then
17+
echo "Installing code-server..."
18+
curl -fsSL https://code-server.dev/install.sh | sh >/dev/null 2>&1
19+
fi
20+
21+
if ! command -v gsutil &> /dev/null; then
22+
echo "Installing Google Cloud SDK..."
23+
sudo apt-get install -y -qq apt-transport-https ca-certificates gnupg >/dev/null
24+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list >/dev/null
25+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - >/dev/null 2>&1
26+
sudo apt-get update -qq >/dev/null && sudo apt-get install -y -qq google-cloud-cli >/dev/null
27+
fi
28+
29+
# 2. Bucket Logic for Syncing Workspace
30+
if [ -n "$BUCKET_NAME" ]; then
31+
GCS_PATH="gs://$BUCKET_NAME/vscode_workspaces/$POD_PATTERN"
32+
echo "Step 2: Syncing with: $GCS_PATH"
33+
34+
# --- Initial Recovery or Init ---
35+
echo " -> Checking GCS for existing files..."
36+
if gsutil ls "$GCS_PATH" >/dev/null 2>&1; then
37+
echo " ✅ Found files! Downloading..."
38+
gsutil -m rsync -r "$GCS_PATH" "$WORKSPACE_DIR"
39+
else
40+
echo " ⚠️ No existing workspace found. initializing..."
41+
# Create a placeholder and upload immediately so directory appears in GCS
42+
touch "$WORKSPACE_DIR/.workspace_init"
43+
gsutil cp "$WORKSPACE_DIR/.workspace_init" "$GCS_PATH/.workspace_init"
44+
echo " ✅ Initialized GCS directory with placeholder."
45+
fi
46+
# --- Background Watcher Process ---
47+
(
48+
echo "Watcher started at $(date)" > $HOME/sync.log
49+
while true; do
50+
inotifywait -r -e modify,create,delete,move "$WORKSPACE_DIR" >> $HOME/sync.log 2>&1
51+
echo "[AutoSync] Change detected. Waiting 5s..." >> $HOME/sync.log
52+
sleep 5
53+
54+
echo "[AutoSync] Syncing (Mirroring)..." >> $HOME/sync.log
55+
# Explicitly use -r (recursive) and -d (delete)
56+
gsutil -m rsync -r -d "$WORKSPACE_DIR" "$GCS_PATH" >> $HOME/sync.log 2>&1
57+
58+
echo "[AutoSync] Done at $(date)" >> $HOME/sync.log
59+
done
60+
) &
61+
else
62+
echo "Step 2: No bucket provided. Skipping sync."
63+
fi
64+
65+
# 3. Launch VS Code
66+
# Kill any existing remote process on this port
67+
kill -9 $(lsof -t -i:$PORT) 2>/dev/null
68+
echo "Step 3: Launching VS Code..."
69+
echo " -> Local URL: http://127.0.0.1:$PORT"
70+
71+
code-server --bind-addr 127.0.0.1:$PORT --auth none "$WORKSPACE_DIR"

0 commit comments

Comments
 (0)