Spaces:
Sleeping
Sleeping
Piyusharanjan Pradhan
commited on
Commit
·
085912f
1
Parent(s):
7c545fe
persist code data
Browse files- Dockerfile +11 -5
- README.md +39 -7
- startup.sh +95 -0
Dockerfile
CHANGED
|
@@ -19,8 +19,13 @@ RUN apt-get update && apt-get install -y \
|
|
| 19 |
python3-pip \
|
| 20 |
nodejs \
|
| 21 |
npm \
|
|
|
|
|
|
|
| 22 |
&& rm -rf /var/lib/apt/lists/*
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
# Install code-server
|
| 25 |
RUN curl -fsSL https://code-server.dev/install.sh | sh
|
| 26 |
|
|
@@ -44,9 +49,6 @@ EXPOSE 7860
|
|
| 44 |
# Create config directory
|
| 45 |
RUN mkdir -p /home/coder/.config/code-server
|
| 46 |
|
| 47 |
-
# Install unzip for extracting extensions
|
| 48 |
-
RUN sudo apt-get update && sudo apt-get install -y unzip && sudo rm -rf /var/lib/apt/lists/*
|
| 49 |
-
|
| 50 |
# Install AI coding assistant extensions that support Gemini
|
| 51 |
RUN code-server --install-extension Continue.continue || true
|
| 52 |
|
|
@@ -59,5 +61,9 @@ RUN echo "bind-addr: 0.0.0.0:7860" > /home/coder/.config/code-server/config.yaml
|
|
| 59 |
echo "password: ${PASSWORD}" >> /home/coder/.config/code-server/config.yaml && \
|
| 60 |
echo "cert: false" >> /home/coder/.config/code-server/config.yaml
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
python3-pip \
|
| 20 |
nodejs \
|
| 21 |
npm \
|
| 22 |
+
unzip \
|
| 23 |
+
rsync \
|
| 24 |
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
|
| 26 |
+
# Install Hugging Face CLI for dataset access
|
| 27 |
+
RUN pip3 install --no-cache-dir huggingface_hub[cli]
|
| 28 |
+
|
| 29 |
# Install code-server
|
| 30 |
RUN curl -fsSL https://code-server.dev/install.sh | sh
|
| 31 |
|
|
|
|
| 49 |
# Create config directory
|
| 50 |
RUN mkdir -p /home/coder/.config/code-server
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
# Install AI coding assistant extensions that support Gemini
|
| 53 |
RUN code-server --install-extension Continue.continue || true
|
| 54 |
|
|
|
|
| 61 |
echo "password: ${PASSWORD}" >> /home/coder/.config/code-server/config.yaml && \
|
| 62 |
echo "cert: false" >> /home/coder/.config/code-server/config.yaml
|
| 63 |
|
| 64 |
+
# Copy startup script
|
| 65 |
+
COPY --chown=coder:coder startup.sh /home/coder/startup.sh
|
| 66 |
+
RUN chmod +x /home/coder/startup.sh
|
| 67 |
+
|
| 68 |
+
# Start code-server with persistence
|
| 69 |
+
CMD ["/home/coder/startup.sh"]
|
README.md
CHANGED
|
@@ -10,25 +10,55 @@ app_port: 7860
|
|
| 10 |
|
| 11 |
# VS Code on Web - Hugging Face Spaces
|
| 12 |
|
| 13 |
-
This Space deploys VS Code in your browser using code-server.
|
| 14 |
|
| 15 |
## Features
|
| 16 |
|
| 17 |
- 🌐 VS Code running in your browser
|
|
|
|
| 18 |
- 🐍 Pre-installed Python 3 and pip
|
| 19 |
- 📦 Node.js and npm included
|
| 20 |
- 🛠️ Build tools and common utilities
|
| 21 |
- 🔒 Password-protected access
|
|
|
|
| 22 |
|
| 23 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
Once deployed, access your VS Code instance through this Space. The default password is `huggingface`.
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
## Configuration
|
| 28 |
|
| 29 |
- **Port**: 7860
|
| 30 |
-
- **Default Password**: `huggingface`
|
| 31 |
- **Workspace Directory**: `/home/coder/workspace`
|
|
|
|
| 32 |
|
| 33 |
## Installed Tools
|
| 34 |
|
|
@@ -37,10 +67,12 @@ Once deployed, access your VS Code instance through this Space. The default pass
|
|
| 37 |
- Node.js with npm
|
| 38 |
- Build essentials (gcc, g++, make)
|
| 39 |
- Text editors (vim, nano)
|
| 40 |
-
-
|
|
|
|
| 41 |
|
| 42 |
## Notes
|
| 43 |
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
-
|
|
|
|
|
|
| 10 |
|
| 11 |
# VS Code on Web - Hugging Face Spaces
|
| 12 |
|
| 13 |
+
This Space deploys VS Code in your browser using code-server with persistent storage via Hugging Face Datasets.
|
| 14 |
|
| 15 |
## Features
|
| 16 |
|
| 17 |
- 🌐 VS Code running in your browser
|
| 18 |
+
- 💾 Persistent storage using Hugging Face Datasets
|
| 19 |
- 🐍 Pre-installed Python 3 and pip
|
| 20 |
- 📦 Node.js and npm included
|
| 21 |
- 🛠️ Build tools and common utilities
|
| 22 |
- 🔒 Password-protected access
|
| 23 |
+
- 🤖 AI coding assistant (Continue) with Gemini support
|
| 24 |
|
| 25 |
+
## Setup
|
| 26 |
+
|
| 27 |
+
### 1. Create a Hugging Face Dataset
|
| 28 |
+
|
| 29 |
+
Create a new private dataset on Hugging Face to store your VS Code data:
|
| 30 |
+
https://huggingface.co/new-dataset
|
| 31 |
+
|
| 32 |
+
### 2. Configure Environment Variables
|
| 33 |
+
|
| 34 |
+
In your Space settings, add these secrets:
|
| 35 |
+
|
| 36 |
+
- `HF_TOKEN`: Your Hugging Face access token (with write permissions)
|
| 37 |
+
- `HF_DATASET`: Your dataset name (e.g., `username/vscode-data`)
|
| 38 |
+
|
| 39 |
+
### 3. Access Your VS Code
|
| 40 |
|
| 41 |
Once deployed, access your VS Code instance through this Space. The default password is `huggingface`.
|
| 42 |
|
| 43 |
+
## How Persistence Works
|
| 44 |
+
|
| 45 |
+
The startup script automatically:
|
| 46 |
+
- Downloads your saved workspace, settings, and extensions from the HF dataset on startup
|
| 47 |
+
- Auto-saves every 5 minutes while running
|
| 48 |
+
- Saves all data when the Space shuts down
|
| 49 |
+
|
| 50 |
+
**Persisted data includes:**
|
| 51 |
+
- VS Code settings and configuration
|
| 52 |
+
- Installed extensions
|
| 53 |
+
- Workspace files and folders
|
| 54 |
+
- Extension settings (including API keys)
|
| 55 |
+
|
| 56 |
## Configuration
|
| 57 |
|
| 58 |
- **Port**: 7860
|
| 59 |
+
- **Default Password**: `huggingface` (change in Dockerfile)
|
| 60 |
- **Workspace Directory**: `/home/coder/workspace`
|
| 61 |
+
- **Auto-save interval**: Every 5 minutes
|
| 62 |
|
| 63 |
## Installed Tools
|
| 64 |
|
|
|
|
| 67 |
- Node.js with npm
|
| 68 |
- Build essentials (gcc, g++, make)
|
| 69 |
- Text editors (vim, nano)
|
| 70 |
+
- Hugging Face CLI
|
| 71 |
+
- Continue extension (supports Gemini, GPT-4, Claude, etc.)
|
| 72 |
|
| 73 |
## Notes
|
| 74 |
|
| 75 |
+
- Without `HF_TOKEN` and `HF_DATASET` set, the Space runs without persistence
|
| 76 |
+
- The first startup takes longer as it sets up the environment
|
| 77 |
+
- Large workspaces may take time to sync
|
| 78 |
+
- Your data is stored in your private HF dataset and not accessible to others
|
startup.sh
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
echo "Starting VS Code with Hugging Face persistence..."
|
| 5 |
+
|
| 6 |
+
# Check if HF_TOKEN and HF_DATASET are set
|
| 7 |
+
if [ -z "$HF_TOKEN" ] || [ -z "$HF_DATASET" ]; then
|
| 8 |
+
echo "Warning: HF_TOKEN or HF_DATASET not set. Running without persistence."
|
| 9 |
+
exec code-server --bind-addr 0.0.0.0:7860 --auth password /home/coder/workspace
|
| 10 |
+
exit 0
|
| 11 |
+
fi
|
| 12 |
+
|
| 13 |
+
# Login to Hugging Face
|
| 14 |
+
echo "Logging in to Hugging Face..."
|
| 15 |
+
huggingface-cli login --token "$HF_TOKEN" --add-to-git-credential
|
| 16 |
+
|
| 17 |
+
# Directories to persist
|
| 18 |
+
CONFIG_DIR="/home/coder/.config/code-server"
|
| 19 |
+
LOCAL_DIR="/home/coder/.local/share/code-server"
|
| 20 |
+
WORKSPACE_DIR="/home/coder/workspace"
|
| 21 |
+
BACKUP_DIR="/tmp/hf_backup"
|
| 22 |
+
|
| 23 |
+
# Create backup directory
|
| 24 |
+
mkdir -p "$BACKUP_DIR"
|
| 25 |
+
|
| 26 |
+
# Function to download from HF dataset
|
| 27 |
+
download_from_hf() {
|
| 28 |
+
echo "Downloading persisted data from Hugging Face dataset: $HF_DATASET"
|
| 29 |
+
|
| 30 |
+
# Try to download the backup archive
|
| 31 |
+
if huggingface-cli download "$HF_DATASET" backup.tar.gz --repo-type dataset --local-dir "$BACKUP_DIR" 2>/dev/null; then
|
| 32 |
+
echo "Found existing backup, restoring..."
|
| 33 |
+
|
| 34 |
+
# Extract the backup
|
| 35 |
+
cd /home/coder
|
| 36 |
+
tar -xzf "$BACKUP_DIR/backup.tar.gz" 2>/dev/null || echo "No previous backup found or extraction failed"
|
| 37 |
+
|
| 38 |
+
echo "Restoration complete!"
|
| 39 |
+
else
|
| 40 |
+
echo "No existing backup found. Starting fresh."
|
| 41 |
+
fi
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
# Function to upload to HF dataset
|
| 45 |
+
upload_to_hf() {
|
| 46 |
+
echo "Saving data to Hugging Face dataset..."
|
| 47 |
+
|
| 48 |
+
# Create backup archive
|
| 49 |
+
cd /home/coder
|
| 50 |
+
tar -czf "$BACKUP_DIR/backup.tar.gz" \
|
| 51 |
+
--exclude='*.log' \
|
| 52 |
+
--exclude='*.sock' \
|
| 53 |
+
--exclude='CachedData' \
|
| 54 |
+
--exclude='Cache' \
|
| 55 |
+
--exclude='GPUCache' \
|
| 56 |
+
.config/code-server \
|
| 57 |
+
.local/share/code-server \
|
| 58 |
+
workspace 2>/dev/null || true
|
| 59 |
+
|
| 60 |
+
# Upload to HF dataset
|
| 61 |
+
huggingface-cli upload "$HF_DATASET" "$BACKUP_DIR/backup.tar.gz" backup.tar.gz --repo-type dataset --create || \
|
| 62 |
+
echo "Upload failed, continuing anyway..."
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
# Setup trap to save on exit
|
| 66 |
+
trap 'upload_to_hf' EXIT SIGTERM SIGINT
|
| 67 |
+
|
| 68 |
+
# Download existing data
|
| 69 |
+
download_from_hf
|
| 70 |
+
|
| 71 |
+
# Start background sync every 5 minutes
|
| 72 |
+
(
|
| 73 |
+
while true; do
|
| 74 |
+
sleep 300
|
| 75 |
+
upload_to_hf
|
| 76 |
+
done
|
| 77 |
+
) &
|
| 78 |
+
|
| 79 |
+
SYNC_PID=$!
|
| 80 |
+
|
| 81 |
+
echo "Starting code-server..."
|
| 82 |
+
# Start code-server
|
| 83 |
+
code-server --bind-addr 0.0.0.0:7860 --auth password /home/coder/workspace &
|
| 84 |
+
CODE_SERVER_PID=$!
|
| 85 |
+
|
| 86 |
+
# Wait for code-server to exit
|
| 87 |
+
wait $CODE_SERVER_PID
|
| 88 |
+
|
| 89 |
+
# Kill background sync
|
| 90 |
+
kill $SYNC_PID 2>/dev/null || true
|
| 91 |
+
|
| 92 |
+
# Final upload
|
| 93 |
+
upload_to_hf
|
| 94 |
+
|
| 95 |
+
echo "Shutdown complete."
|