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