jonathanagustin commited on
Commit
6dbf4a6
·
verified ·
1 Parent(s): 6fe9185

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +1 -0
  2. app.py +16 -5
README.md CHANGED
@@ -14,6 +14,7 @@ Set these as HuggingFace Secrets:
14
 
15
  - `REGISTRY_USER`: GitHub username
16
  - `REGISTRY_PASSWORD`: GitHub PAT with `packages:write` scope
 
17
  - `UPSTASH_REDIS_REST_URL`: (optional) Redis URL for build queue
18
  - `UPSTASH_REDIS_REST_TOKEN`: (optional) Redis token
19
 
 
14
 
15
  - `REGISTRY_USER`: GitHub username
16
  - `REGISTRY_PASSWORD`: GitHub PAT with `packages:write` scope
17
+ - `GITHUB_TOKEN`: (optional) GitHub PAT for cloning private repositories
18
  - `UPSTASH_REDIS_REST_URL`: (optional) Redis URL for build queue
19
  - `UPSTASH_REDIS_REST_TOKEN`: (optional) Redis token
20
 
app.py CHANGED
@@ -35,6 +35,7 @@ RUNNER_NAME = os.environ.get("RUNNER_NAME", f"Builder {RUNNER_ID}")
35
  REGISTRY_URL = os.environ.get("REGISTRY_URL", "ghcr.io")
36
  REGISTRY_USER = os.environ.get("REGISTRY_USER", "")
37
  REGISTRY_PASSWORD = os.environ.get("REGISTRY_PASSWORD", "")
 
38
  AUTO_START = os.environ.get("AUTO_START", "false").lower() == "true"
39
 
40
  # Global state
@@ -157,16 +158,25 @@ def setup_registry_auth():
157
  # Build Logic
158
  # =============================================================================
159
 
160
- def clone_repo(repo_url: str, branch: str = "main", target_dir: Path = None) -> Path:
161
- """Clone a git repository."""
162
  if target_dir is None:
163
  target_dir = Path(tempfile.mkdtemp())
164
 
165
- log(f"Cloning {repo_url} ({branch})...")
 
 
 
 
 
 
 
 
 
166
 
167
  try:
168
  git.Repo.clone_from(
169
- repo_url,
170
  target_dir,
171
  branch=branch,
172
  depth=1,
@@ -294,6 +304,7 @@ def run_build(build_config: dict) -> bool:
294
  context_path = build_config.get("context_path", ".")
295
  tags = build_config.get("tags", ["latest"])
296
  build_args = build_config.get("build_args", {})
 
297
 
298
  if not repo_url or not image_name:
299
  log("✗ Missing repo_url or image_name")
@@ -302,7 +313,7 @@ def run_build(build_config: dict) -> bool:
302
  tmpdir = None
303
  try:
304
  # Clone repo
305
- tmpdir = clone_repo(repo_url, branch)
306
 
307
  # Set context directory
308
  context_dir = str(tmpdir / context_path) if context_path != "." else str(tmpdir)
 
35
  REGISTRY_URL = os.environ.get("REGISTRY_URL", "ghcr.io")
36
  REGISTRY_USER = os.environ.get("REGISTRY_USER", "")
37
  REGISTRY_PASSWORD = os.environ.get("REGISTRY_PASSWORD", "")
38
+ GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN", "") # For cloning private repos
39
  AUTO_START = os.environ.get("AUTO_START", "false").lower() == "true"
40
 
41
  # Global state
 
158
  # Build Logic
159
  # =============================================================================
160
 
161
+ def clone_repo(repo_url: str, branch: str = "main", target_dir: Path = None, github_token: str = None) -> Path:
162
+ """Clone a git repository, with optional GitHub token for private repos."""
163
  if target_dir is None:
164
  target_dir = Path(tempfile.mkdtemp())
165
 
166
+ # Use GitHub token if provided or from env, for private repos
167
+ token = github_token or GITHUB_TOKEN
168
+ auth_url = repo_url
169
+
170
+ if token and "github.com" in repo_url:
171
+ # Insert token into URL for auth: https://TOKEN@github.com/...
172
+ auth_url = repo_url.replace("https://github.com", f"https://{token}@github.com")
173
+ log(f"Cloning {repo_url} ({branch}) [authenticated]...")
174
+ else:
175
+ log(f"Cloning {repo_url} ({branch})...")
176
 
177
  try:
178
  git.Repo.clone_from(
179
+ auth_url,
180
  target_dir,
181
  branch=branch,
182
  depth=1,
 
304
  context_path = build_config.get("context_path", ".")
305
  tags = build_config.get("tags", ["latest"])
306
  build_args = build_config.get("build_args", {})
307
+ github_token = build_config.get("github_token") # Optional per-build token
308
 
309
  if not repo_url or not image_name:
310
  log("✗ Missing repo_url or image_name")
 
313
  tmpdir = None
314
  try:
315
  # Clone repo
316
+ tmpdir = clone_repo(repo_url, branch, github_token=github_token)
317
 
318
  # Set context directory
319
  context_dir = str(tmpdir / context_path) if context_path != "." else str(tmpdir)