Update db_url default, add env_file and volumes in Docker, enhance logging
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ wheels/
|
||||
# Virtual environments
|
||||
.venv
|
||||
|
||||
.env
|
||||
.env*
|
||||
.ruff_cache
|
||||
|
||||
*.sqlite
|
||||
|
||||
@@ -5,6 +5,7 @@ WORKDIR /app
|
||||
ENV UV_COMPILE_BYTECODE=1
|
||||
|
||||
ADD pyproject.toml uv.lock .
|
||||
RUN mkdir -p /app/data
|
||||
RUN uv sync --frozen --no-dev
|
||||
|
||||
ADD /src .
|
||||
|
||||
@@ -6,6 +6,18 @@ services:
|
||||
dockerfile: Dockerfile
|
||||
image: pjl-backend:1.0rc1
|
||||
|
||||
env_file:
|
||||
- .env.prod
|
||||
|
||||
Environment:
|
||||
DB_URL: /app/data/pjl.duckdb
|
||||
DEFAULT_AVATAR_URL: https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=Kingston
|
||||
OMDB_API_KEY: ${OMDB_API_KEY}
|
||||
STAGE: prod
|
||||
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
|
||||
# Host the FastAPI application on port 8000
|
||||
ports:
|
||||
- "8000:8000"
|
||||
|
||||
@@ -3,12 +3,14 @@ import duckdb
|
||||
import bcrypt
|
||||
|
||||
from lib import settings
|
||||
from lib.logger import logger
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_db():
|
||||
try:
|
||||
conn = duckdb.connect(database=settings.db_url)
|
||||
logger.debug(f"Connecting to database {settings.db_url.absolute()}")
|
||||
conn = duckdb.connect(database=settings.db_url.absolute())
|
||||
yield conn
|
||||
finally:
|
||||
conn.close()
|
||||
@@ -22,10 +24,11 @@ def db_run(sql, values: tuple = None):
|
||||
|
||||
def init_db():
|
||||
if settings.db_url.exists():
|
||||
pass
|
||||
# TODO: Development feature. Remove this in production
|
||||
from os import unlink
|
||||
# from os import unlink
|
||||
|
||||
unlink(settings.db_url)
|
||||
# unlink(settings.db_url)
|
||||
sql = ""
|
||||
with open("lib/database/database.sql") as f:
|
||||
sql = f.read()
|
||||
|
||||
+1
-4
@@ -4,15 +4,12 @@ from pathlib import Path
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
db_url: Path = Field(Path("pjl.duckdb"), env="DB_URL")
|
||||
db_url: Path = Field(Path("pjl_default.duckdb"), env="DB_URL")
|
||||
default_avatar_url: str = Field(
|
||||
"https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=Kingston",
|
||||
env="DEFAULT_AVATAR_URL",
|
||||
)
|
||||
OMDB_API_KEY: str = Field(env="OMDB_API_KEY")
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
||||
Reference in New Issue
Block a user