Spaces:
Sleeping
Sleeping
File size: 2,388 Bytes
c12eb19 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """Upload the Docker Space from the lobby PC through HTTP(S)_PROXY.
Do not save the HF access token into any project files.
"""
from __future__ import annotations
import json
import os
from pathlib import Path
import secrets
import time
from huggingface_hub import HfApi
root = Path(__file__).resolve().parents[1]
token = os.getenv("HF_TOKEN","").strip()
if not token:
raise SystemExit("HF_TOKEN environment variable is required.")
api = HfApi(token=token)
username = api.whoami()["name"]
repo = os.getenv("HF_SPACE_REPO",f"{username}/ahp-development-workstation")
if not repo.startswith(username + "/"):
raise SystemExit("Account mismatch. Refusing to upload to an unrelated account.")
# Keep credentials OUTSIDE the Space folder so re-upload cannot leak them.
creds_path = root.parent / "HF-AhpDevSpace-20261012-credentials.txt"
creds = {}
if creds_path.is_file():
for line in creds_path.read_text(encoding="utf-8").splitlines():
if ": " in line:
k,v = line.split(": ",1)
creds[k] = v
ide_pass = os.getenv("HF_IDE_PASSWORD") or creds.get("IDE password") or secrets.token_urlsafe(30)
mcp_key = os.getenv("HF_MCP_KEY") or creds.get("MCP API Key") or secrets.token_urlsafe(40)
creds_path.write_text("Space: https://huggingface.co/spaces/" + repo +
"\nIDE password: " + ide_pass +
"\nMCP API Key: " + mcp_key + "\n",encoding="utf-8")
print("Account verified:",username,flush=True)
print("Creating Docker Space repository:",repo,flush=True)
api.create_repo(repo_id=repo,repo_type="space",space_sdk="docker",private=False,exist_ok=True)
api.add_space_secret(repo,"CODE_SERVER_PASSWORD",ide_pass)
api.add_space_secret(repo,"MCP_API_KEY",mcp_key)
print("Space secrets configured; credentials stored on lobby PC outside project directory.",flush=True)
info=api.upload_folder(
repo_id=repo,repo_type="space",folder_path=str(root),
commit_message="Install complete Linux VS Code + AHP MCP development workstation 2026-10-12",
ignore_patterns=["*.log","*.pdb","__pycache__/*","*.pyc","*.bak","*.tmp"])
print("PUBLISHED",f"https://huggingface.co/spaces/{repo}",flush=True)
print("COMMIT",str(info),flush=True)
try:
state=api.get_space_runtime(repo)
print("SPACE_STAGE",state.stage,flush=True)
except Exception as exc:
print("SPACE_STAGE_PENDING",type(exc).__name__,str(exc)[:240],flush=True)
|