config: fix media path at /var/thoughtsync (no env knob)
The media/data location is no longer configurable — DATA_DIR is a fixed constant (/var/thoughtsync) and THOUGHTSYNC_MEDIA_ROOT is removed, so a mutable path can't drift from where the volume is mounted. media_root() = DATA_DIR/media. Both compose files drop THOUGHTSYNC_DATA_DIR and mount the data volume at /var/thoughtsync (was the contradictory /data). conftest drops the stale MEDIA_ROOT monkeypatch (create_app never reads DATA_DIR). Net env surface: THOUGHTSYNC_DATABASE_URL (required) + THOUGHTSYNC_SECRET_KEY (optional break-glass). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
This commit is contained in:
@@ -31,14 +31,13 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
environment:
|
environment:
|
||||||
THOUGHTSYNC_DATABASE_URL: postgresql+asyncpg://thoughtsync:thoughtsync@db:5432/thoughtsync
|
THOUGHTSYNC_DATABASE_URL: postgresql+asyncpg://thoughtsync:thoughtsync@db:5432/thoughtsync
|
||||||
THOUGHTSYNC_DATA_DIR: /data
|
|
||||||
PYTHONPATH: /app/src
|
PYTHONPATH: /app/src
|
||||||
volumes:
|
volumes:
|
||||||
- ./pyproject.toml:/app/pyproject.toml
|
- ./pyproject.toml:/app/pyproject.toml
|
||||||
- ./alembic.ini:/app/alembic.ini
|
- ./alembic.ini:/app/alembic.ini
|
||||||
- ./alembic:/app/alembic
|
- ./alembic:/app/alembic
|
||||||
- ./src:/app/src
|
- ./src:/app/src
|
||||||
- thoughtsync-dev-data:/data
|
- thoughtsync-dev-data:/var/thoughtsync
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "5000:5000"
|
||||||
# Install deps, run migrations, then serve with live reload on the mounted src.
|
# Install deps, run migrations, then serve with live reload on the mounted src.
|
||||||
|
|||||||
+1
-2
@@ -24,9 +24,8 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
environment:
|
environment:
|
||||||
THOUGHTSYNC_DATABASE_URL: postgresql+asyncpg://thoughtsync:thoughtsync@db:5432/thoughtsync
|
THOUGHTSYNC_DATABASE_URL: postgresql+asyncpg://thoughtsync:thoughtsync@db:5432/thoughtsync
|
||||||
THOUGHTSYNC_DATA_DIR: /data
|
|
||||||
volumes:
|
volumes:
|
||||||
- thoughtsync-data:/data
|
- thoughtsync-data:/var/thoughtsync
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "5000:5000"
|
||||||
|
|
||||||
|
|||||||
@@ -8,19 +8,21 @@ class Config:
|
|||||||
"""Bootstrap configuration.
|
"""Bootstrap configuration.
|
||||||
|
|
||||||
For a basic install, ``THOUGHTSYNC_DATABASE_URL`` is the ONLY required env var —
|
For a basic install, ``THOUGHTSYNC_DATABASE_URL`` is the ONLY required env var —
|
||||||
every other tunable lives in the DB-backed Settings UI (rule 25). The remaining
|
every other tunable lives in the DB-backed Settings UI (rule 25). The only other
|
||||||
env vars are optional "break-glass" / bootstrap items:
|
env var is an optional "break-glass" item:
|
||||||
|
|
||||||
- ``THOUGHTSYNC_SECRET_KEY`` — optional override for the cookie-signing secret.
|
- ``THOUGHTSYNC_SECRET_KEY`` — optional override for the cookie-signing secret.
|
||||||
If unset, a key is generated and persisted in the DB (see
|
If unset, a key is generated and persisted in the DB (see
|
||||||
``thoughtsync.settings.load_or_create_secret_key``), so sessions survive
|
``thoughtsync.settings.load_or_create_secret_key``), so sessions survive
|
||||||
restarts with no volume required.
|
restarts with no volume required.
|
||||||
- ``THOUGHTSYNC_DATA_DIR`` — optional, defaults to ``/var/thoughtsync``. Only
|
|
||||||
used for uploaded media (M2); irrelevant to a basic text-notes install.
|
Uploaded media lives under ``DATA_DIR`` — a fixed, authoritative path
|
||||||
|
(``/var/thoughtsync``), intentionally NOT configurable (a mutable data path only
|
||||||
|
invites breakage). Mount a volume there if you want uploads to persist across
|
||||||
|
container recreation; a text-notes-only install never writes to it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DATA_DIR = os.environ.get("THOUGHTSYNC_DATA_DIR", "/var/thoughtsync")
|
DATA_DIR = "/var/thoughtsync"
|
||||||
MEDIA_ROOT = os.environ.get("THOUGHTSYNC_MEDIA_ROOT", "")
|
|
||||||
|
|
||||||
DATABASE_URL = os.environ.get(
|
DATABASE_URL = os.environ.get(
|
||||||
"THOUGHTSYNC_DATABASE_URL",
|
"THOUGHTSYNC_DATABASE_URL",
|
||||||
@@ -29,7 +31,7 @@ class Config:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def media_root(cls) -> Path:
|
def media_root(cls) -> Path:
|
||||||
return Path(cls.MEDIA_ROOT or os.path.join(cls.DATA_DIR, "media"))
|
return Path(cls.DATA_DIR) / "media"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def secret_key_env(cls) -> str | None:
|
def secret_key_env(cls) -> str | None:
|
||||||
|
|||||||
+4
-5
@@ -5,9 +5,8 @@ from thoughtsync.config import Config
|
|||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def _isolated_data_dir(tmp_path, monkeypatch):
|
def _isolated_data_dir(tmp_path, monkeypatch):
|
||||||
"""Point DATA_DIR at a writable temp dir so create_app() can generate its
|
"""Keep any media writes on an isolated temp dir rather than the fixed
|
||||||
signing key without needing /var/thoughtsync to exist (DB-free unit tests)."""
|
/var/thoughtsync. DB-free unit tests never actually hit it (create_app takes its
|
||||||
data_dir = tmp_path / "data"
|
signing key from env-or-random, not a file), but this stays defensive."""
|
||||||
monkeypatch.setattr(Config, "DATA_DIR", str(data_dir))
|
monkeypatch.setattr(Config, "DATA_DIR", str(tmp_path / "data"))
|
||||||
monkeypatch.setattr(Config, "MEDIA_ROOT", str(data_dir / "media"))
|
|
||||||
yield
|
yield
|
||||||
|
|||||||
Reference in New Issue
Block a user