Spaces:
Sleeping
Sleeping
Commit ·
47de723
1
Parent(s): 6c01270
fix(deploy): writable pretrained dir + safe mkdir fallback
Browse filespretrained_registry imported at module load time tried to mkdir
/app/pretrained, which the app user can't write to. Two fixes:
1. Dockerfile now creates /app/pretrained and chowns it to app:app.
2. Module-level mkdir is wrapped in try/except so import never crashes;
warning logged instead. PRETRAINED_DIR overridable via env for hosts
with a read-only app dir (point at /tmp/pretrained on Render free).
Fixes: 'Analiz hatasi: [Errno 13] Permission denied: /app/pretrained'
on every /inspect call.
services/backend/Dockerfile
CHANGED
|
@@ -78,7 +78,8 @@ COPY --chown=app:app parts.yaml ./
|
|
| 78 |
|
| 79 |
COPY --chown=app:app scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
|
| 80 |
RUN chmod +x /usr/local/bin/entrypoint.sh && \
|
| 81 |
-
mkdir -p ${MODEL_DIR} &&
|
|
|
|
| 82 |
|
| 83 |
USER app
|
| 84 |
|
|
|
|
| 78 |
|
| 79 |
COPY --chown=app:app scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
|
| 80 |
RUN chmod +x /usr/local/bin/entrypoint.sh && \
|
| 81 |
+
mkdir -p ${MODEL_DIR} /app/pretrained && \
|
| 82 |
+
chown -R app:app ${MODEL_DIR} /app/pretrained
|
| 83 |
|
| 84 |
USER app
|
| 85 |
|
services/backend/pretrained_registry.py
CHANGED
|
@@ -38,8 +38,20 @@ from typing import Any, Dict, List, Optional
|
|
| 38 |
# Paths
|
| 39 |
# ---------------------------------------------------------------------------
|
| 40 |
ML_ROOT = Path(__file__).resolve().parent
|
| 41 |
-
PRETRAINED_DIR
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
# ---------------------------------------------------------------------------
|
|
|
|
| 38 |
# Paths
|
| 39 |
# ---------------------------------------------------------------------------
|
| 40 |
ML_ROOT = Path(__file__).resolve().parent
|
| 41 |
+
# PRETRAINED_DIR is overridable via env (PRETRAINED_DIR) so production hosts
|
| 42 |
+
# with a read-only application dir can point it at writable scratch space
|
| 43 |
+
# (e.g. /tmp/pretrained on Render, /data on Fly.io).
|
| 44 |
+
PRETRAINED_DIR = Path(os.getenv("PRETRAINED_DIR", str(ML_ROOT / "pretrained")))
|
| 45 |
+
try:
|
| 46 |
+
PRETRAINED_DIR.mkdir(parents=True, exist_ok=True)
|
| 47 |
+
except (PermissionError, OSError) as _e:
|
| 48 |
+
import logging as _logging
|
| 49 |
+
_logging.warning(
|
| 50 |
+
"pretrained_registry: cannot create %s (%s). Set PRETRAINED_DIR env to "
|
| 51 |
+
"a writable path or rebuild image with chown on this directory. "
|
| 52 |
+
"Pretrained model downloads will fail until then.",
|
| 53 |
+
PRETRAINED_DIR, _e,
|
| 54 |
+
)
|
| 55 |
|
| 56 |
|
| 57 |
# ---------------------------------------------------------------------------
|