yageV5 commited on
Commit
b79920e
·
verified ·
1 Parent(s): 787c7f4

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +169 -8
  2. app.py +30 -0
  3. backup.py +63 -0
  4. gitattributes +35 -0
  5. restore.py +30 -0
README.md CHANGED
@@ -1,12 +1,173 @@
1
  ---
2
- title: Vscode2
3
- emoji: 🏆
4
- colorFrom: red
5
- colorTo: pink
6
  sdk: docker
7
- pinned: false
8
- license: apache-2.0
9
- short_description: ziyongxuexi
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Visual Studio Code
3
+ emoji: 💻
4
+ colorFrom: blue
5
+ colorTo: indigo
6
  sdk: docker
7
+ pinned: true
8
+ license: mit
9
+ short_description: An online VS Code on the Web, now equipped with toolchains.
10
  ---
11
 
12
+ # 💻 VS Code on the Web IDE with Auto Backup
13
+
14
+ This Space runs **VS Code on the Web** with a **full developer toolchain**, ready for mega collaboration:
15
+
16
+ # Checklist
17
+
18
+ ## Compilers / Runtimes (Installed)
19
+ - Python ✔ (3.12.11 64-bit, pip 25.2)
20
+ - C (gcc) ✔ (11.4.0)
21
+ - C++ (g++) ✔ (11.4.0)
22
+ - Clang ✔ (14.0.0)
23
+ - Fortran ✔ (11.4.0)
24
+ - Rust ✔ (rustc 1.89.0, cargo 1.89.0)
25
+ - Go ✔ (1.23.0)
26
+ - Java ✔ (OpenJDK 17.0.16, javac 17.0.16)
27
+ - .NET / C# ✔ (dotnet SDK 8.0.413)
28
+ - Node.js ✔ (v20.19.5, npm 10.8.2)
29
+ - Yarn ✔ (global, latest)
30
+ - pnpm ✔ (global, latest)
31
+
32
+ ## Compilers (Planned)
33
+ - Haskell ✖ (ghc + cabal)
34
+ - Julia ✖
35
+ - Scala ✖ (scala + sbt)
36
+ - PHP ✖ (php + composer)
37
+ - Ruby ✖
38
+
39
+ ---
40
+
41
+ ## Build Tools
42
+ - GNU Make ✔ (4.3)
43
+ - CMake ✔ (3.22.1)
44
+ - Ninja ✔ (1.10.1)
45
+ - pkg-config ✔
46
+ - LLVM toolchain ✔ (llvm, clang, lld, lldb)
47
+ - Valgrind ✔
48
+ - GDB ✔
49
+ - Strace ✔
50
+ - Ltrace ✔
51
+
52
+ ## Build Tools (Planned)
53
+ - pigz ✖
54
+ - lcov ✖
55
+ - zlib1g-dev ✖
56
+ - libssl-dev ✖
57
+ - libffi-dev ✖
58
+ - autoconf ✖
59
+ - automake ✖
60
+ - libtool ✖
61
+ - m4 ✖
62
+ - nasm ✖
63
+ - yasm ✖
64
+ - graphviz ✖
65
+ - doxygen ✖
66
+
67
+ ---
68
+
69
+ ## Dev/Utility Tools
70
+ - Git ✔
71
+ - Git LFS ✔
72
+ - Git Extras ✔
73
+ - curl ✔
74
+ - wget ✔
75
+ - unzip ✔
76
+ - rsync ✔
77
+ - sqlite3 ✔
78
+ - jq ✔
79
+ - htop ✔
80
+ - fzf ✔
81
+ - Silver Searcher (ag) ✔
82
+ - ripgrep (rg) ✔
83
+ - tree ✔
84
+ - net-tools ✔
85
+ - iputils-ping ✔
86
+
87
+ ## Debug + Productivity
88
+ - tmux ✖
89
+ - screen ✖
90
+ - neovim ✖
91
+ - httpie ✖
92
+ - shellcheck ✖
93
+ - man-db ✖
94
+ - manpages-dev ✖
95
+
96
+ ---
97
+
98
+ ## Code Tools (npm + pip)
99
+ ### npm
100
+ - typescript ✔
101
+ - ts-node ✔
102
+ - nodemon ✔
103
+
104
+ ### pip
105
+ - black ✔
106
+ - flake8 ✔
107
+ - mypy ✔
108
+ - jupyterlab ✔
109
+ - ipython ✔
110
+ - notebook ✔
111
+ - huggingface_hub ✔
112
+ - hf_transfer ✔ (with env activated for high-speed upload)
113
+
114
+ ## pip Packages (Planned)
115
+ - numpy ✖
116
+ - scipy ✖
117
+ - pandas ✖
118
+ - matplotlib ✖
119
+ - seaborn ✖
120
+ - scikit-learn ✖
121
+ - jupyter ✖
122
+ - torch ✖
123
+ - torchvision ✖
124
+ - torchaudio ✖
125
+ - tensorflow ✖
126
+ - keras ✖
127
+ - datasets ✖
128
+ - transformers ✖
129
+ - accelerate ✖
130
+
131
+ ---
132
+
133
+ ## Database Clients (Planned)
134
+ - mysql-client ✖
135
+ - postgresql-client ✖
136
+ - redis-tools ✖
137
+ - mongodb-clients ✖
138
+
139
+ ---
140
+
141
+ ## Extra Features (WIP)
142
+ - Global npm install directory: `~/npm_pkg_glob` (to avoid sudo & path issues)
143
+
144
+
145
+ ### 🔒 Security Hardening
146
+
147
+ - **Bash history is disabled globally**:
148
+ All interactive shells inside this container are launched with:
149
+ - `HISTFILE` unset
150
+ - `HISTSIZE=0`, `HISTFILESIZE=0`
151
+ - `.bash_history` linked to `/dev/null`
152
+
153
+ 👉 This ensures **no command history is ever logged to disk**, protecting sensitive tokens and commands.
154
+
155
+ ---
156
+
157
+ ### 🗂️ Auto Backup
158
+
159
+ This feature is still WIP. Stay tuned!
160
+
161
+ ---
162
+
163
+ ### ⚠️ Important Notes
164
+
165
+ 1. I **STRONGLY ADVISE** against putting credentials directly into the IDE. If you must use them, *remove them immediately* after use to prevent accidental leaks and misuse.
166
+ 2. All command history is disabled for your safety — but *always treat the `/workspace` folder contents as sensitive*.
167
+ 3. If you plan to duplicate this Space for backups, **DO NOT** make the Space public! Environment variables in Hugging Face Spaces can be exposed to anyone with container access (e.g., via `env`, `printenv`, or process inspection).
168
+ 4. I am **NOT** responsible for any damages caused by leaked passwords/tokens from this Space — so take extreme care with your credentials.
169
+
170
+ ### ℹ️ Additional Notes
171
+
172
+ - Since this Space is hosted remotely (not local), you may experience some latency when performing actions.
173
+ - This IDE is designed for collaborative coding — so feel free to invite friends and enjoy a **feature-packed online coding adventure**! 🚀
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import threading
4
+
5
+ def start_backup_service():
6
+ proc = subprocess.Popen(
7
+ ["python3", "/backup.py"],
8
+ stdout=subprocess.PIPE,
9
+ stderr=subprocess.STDOUT,
10
+ text=True,
11
+ bufsize=1
12
+ )
13
+ # Stream logs in real-time
14
+ for line in proc.stdout:
15
+ print("[Backup]", line.strip())
16
+
17
+ print("Starting Restorer.")
18
+ subprocess.run(["python3", "/restore.py"], check=True)
19
+ print("Finished.")
20
+
21
+ print("Starting Auto-Backup Service.")
22
+ thr = threading.Thread(target=start_backup_service, daemon=True)
23
+ thr.start()
24
+
25
+ print("Starting Coder server.")
26
+ subprocess.run([
27
+ "code-server",
28
+ "--bind-addr", "0.0.0.0:7860",
29
+ "/home/vscode/workspace"
30
+ ])
backup.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ import subprocess
4
+ import datetime
5
+
6
+ BACKUP_REPO = os.environ.get("BACKUP_REPO")
7
+ HF_TOKEN = os.environ.get("HF_TOKEN")
8
+
9
+ def run_backup():
10
+ env = os.environ.copy()
11
+ env["HF_HOME"] = "/tmp/hf_cache"
12
+ env["XDG_CACHE_HOME"] = "/tmp/xdg_cache"
13
+ env["TMPDIR"] = "/tmp"
14
+ env["HF_TOKEN"] = HF_TOKEN
15
+
16
+ os.makedirs(env["HF_HOME"], exist_ok=True)
17
+ os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)
18
+ os.makedirs(env["TMPDIR"], exist_ok=True)
19
+
20
+ local_path = "/home/vscode/workspace"
21
+
22
+ # --- STEP 1: Delete old files ---
23
+ print("[Backup] Deleting old files...")
24
+ cmd = [
25
+ "hf", "repo-files", "delete", BACKUP_REPO, "workspace/",
26
+ "--repo-type", "dataset",
27
+ ]
28
+ process = subprocess.Popen(
29
+ cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
30
+ env=env, text=True, cwd="/tmp"
31
+ )
32
+ for line in iter(process.stdout.readline, ""):
33
+ print("[Backup]", line.strip())
34
+ process.wait()
35
+
36
+ # --- STEP 2: Upload new backup ---
37
+ print("[Backup] Uploading workspace...")
38
+ cmd = [
39
+ "hf", "upload", BACKUP_REPO, local_path, "workspace/",
40
+ "--repo-type", "dataset",
41
+ ]
42
+ process = subprocess.Popen(
43
+ cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
44
+ env=env, text=True, cwd="/tmp"
45
+ )
46
+ for line in iter(process.stdout.readline, ""):
47
+ print("[Backup]", line.strip())
48
+ process.wait()
49
+
50
+ print("[Backup] Completed at", datetime.datetime.utcnow().isoformat(), "UTC")
51
+
52
+ if __name__ == "__main__":
53
+ if not BACKUP_REPO or not HF_TOKEN:
54
+ print("[Backup] BACKUP_REPO or HF_TOKEN not set! Please set it in your Spaces secrets to use the Backup Service.")
55
+ exit(0)
56
+
57
+ while True:
58
+ print("[Backup] Backup started.")
59
+ try:
60
+ run_backup()
61
+ except Exception as e:
62
+ print("[Backup] Failed:", e)
63
+ time.sleep(45 * 60) # 45 minutes
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
restore.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import tempfile
4
+ import shutil
5
+
6
+ BACKUP_REPO = os.environ.get("BACKUP_REPO")
7
+ HF_TOKEN = os.environ.get("HF_TOKEN")
8
+
9
+ if not BACKUP_REPO or not HF_TOKEN:
10
+ print("[Restore] Skipping: BACKUP_REPO or HF_TOKEN not set")
11
+ exit(0)
12
+
13
+ env = os.environ.copy()
14
+ env["HF_HOME"] = "/tmp/hf_cache"
15
+ env["XDG_CACHE_HOME"] = "/tmp/xdg_cache"
16
+ env["TMPDIR"] = "/tmp"
17
+ env["HF_TOKEN"] = HF_TOKEN
18
+
19
+ os.makedirs(env["HF_HOME"], exist_ok=True)
20
+ os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)
21
+ os.makedirs(env["TMPDIR"], exist_ok=True)
22
+
23
+ subprocess.run(
24
+ ["hf", "download", BACKUP_REPO, "--repo-type", "dataset", "--local-dir", "/home/vscode", "--force", "--exclude", ".gitattributes", "--exclude", "*.md"],
25
+ check=True,
26
+ env=env,
27
+ )
28
+
29
+
30
+ print("[Restore] Completed")