Spaces:
Paused
Paused
Update entrypoint.py
Browse files- entrypoint.py +22 -9
entrypoint.py
CHANGED
|
@@ -1,9 +1,15 @@
|
|
| 1 |
-
import subprocess, threading, os
|
| 2 |
from autobackup import schedule_backups
|
| 3 |
from restore import restore_workspace
|
| 4 |
|
| 5 |
password = os.environ.get("VSCODE_PASS", "changeme")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# First restore
|
| 8 |
try:
|
| 9 |
restore_workspace()
|
|
@@ -13,24 +19,31 @@ except Exception as e:
|
|
| 13 |
# Start auto-backup thread
|
| 14 |
threading.Thread(target=schedule_backups, daemon=True).start()
|
| 15 |
|
| 16 |
-
# Write config.yaml
|
| 17 |
-
|
| 18 |
-
with open(
|
| 19 |
f.write(f"""bind-addr: 0.0.0.0:7860
|
| 20 |
auth: password
|
| 21 |
password: {password}
|
| 22 |
cert: false
|
| 23 |
""")
|
| 24 |
|
| 25 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
cmd = [
|
| 27 |
"code-server",
|
| 28 |
"--bind-addr", "0.0.0.0:7860",
|
| 29 |
"--auth", "password",
|
| 30 |
-
"--
|
| 31 |
-
"--
|
| 32 |
"/workspace"
|
| 33 |
]
|
| 34 |
|
| 35 |
-
process = subprocess.Popen(cmd)
|
| 36 |
-
process.wait()
|
|
|
|
| 1 |
+
import subprocess, threading, os
|
| 2 |
from autobackup import schedule_backups
|
| 3 |
from restore import restore_workspace
|
| 4 |
|
| 5 |
password = os.environ.get("VSCODE_PASS", "changeme")
|
| 6 |
|
| 7 |
+
# Ensure correct home/config/data dirs
|
| 8 |
+
home = "/home/coder"
|
| 9 |
+
os.makedirs(f"{home}/.config/code-server", exist_ok=True)
|
| 10 |
+
os.makedirs(f"{home}/.local/share/code-server", exist_ok=True)
|
| 11 |
+
os.makedirs(f"{home}/.cache", exist_ok=True)
|
| 12 |
+
|
| 13 |
# First restore
|
| 14 |
try:
|
| 15 |
restore_workspace()
|
|
|
|
| 19 |
# Start auto-backup thread
|
| 20 |
threading.Thread(target=schedule_backups, daemon=True).start()
|
| 21 |
|
| 22 |
+
# Write config.yaml
|
| 23 |
+
config_path = f"{home}/.config/code-server/config.yaml"
|
| 24 |
+
with open(config_path, "w") as f:
|
| 25 |
f.write(f"""bind-addr: 0.0.0.0:7860
|
| 26 |
auth: password
|
| 27 |
password: {password}
|
| 28 |
cert: false
|
| 29 |
""")
|
| 30 |
|
| 31 |
+
# Prepare environment
|
| 32 |
+
env = os.environ.copy()
|
| 33 |
+
env["HOME"] = home
|
| 34 |
+
env["XDG_CONFIG_HOME"] = f"{home}/.config"
|
| 35 |
+
env["XDG_DATA_HOME"] = f"{home}/.local/share"
|
| 36 |
+
env["XDG_CACHE_HOME"] = f"{home}/.cache"
|
| 37 |
+
|
| 38 |
+
# Run code-server with explicit config + data dirs
|
| 39 |
cmd = [
|
| 40 |
"code-server",
|
| 41 |
"--bind-addr", "0.0.0.0:7860",
|
| 42 |
"--auth", "password",
|
| 43 |
+
"--config", config_path,
|
| 44 |
+
"--user-data-dir", f"{home}/.local/share/code-server",
|
| 45 |
"/workspace"
|
| 46 |
]
|
| 47 |
|
| 48 |
+
process = subprocess.Popen(cmd, env=env)
|
| 49 |
+
process.wait()
|