From 9ecdc1b04050b95630b7aa5b0758bc596d4e9468 Mon Sep 17 00:00:00 2001 From: Esa Kataja Date: Tue, 13 May 2025 21:10:32 +0300 Subject: [PATCH] Fix container not starting if data dir did not exist --- Dockerfile | 1 + src/lib/db.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index f68f4bf..afd79ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,4 +12,5 @@ FROM base COPY --from=builder /app /app ENV PATH="/app/.venv/bin:$PATH" WORKDIR /app +RUN mkdir -p /app/data CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/src/lib/db.py b/src/lib/db.py index 151d019..0b8c013 100644 --- a/src/lib/db.py +++ b/src/lib/db.py @@ -79,8 +79,12 @@ def seed_db() -> None: def init_db(): + logger.info("Initializing database...") if Path(DB_PATH).exists(): return + logger.info("Database does not exist, creating...") + if not Path(DB_PATH).parent.exists(): + Path(DB_PATH).parent.mkdir(parents=True, exist_ok=True) with open(SQL_PATH, "r") as f: sql = f.read() with get_connection() as conn: