Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
FROM python:3.13-slim

WORKDIR /app/

# Install Poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
RUN pip install poetry && \
poetry config virtualenvs.create false

# Copy poetry.lock* in case it doesn't exist in the repo
Expand All @@ -22,4 +20,7 @@ ARG INSTALL_JUPYTER=false
RUN bash -c "if [ $INSTALL_JUPYTER == 'true' ] ; then pip install jupyterlab ; fi"

COPY . /app
ENV PYTHONPATH=/app
ENV PYTHONPATH=/app

EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
20 changes: 8 additions & 12 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Optional

from pydantic import BaseSettings, PostgresDsn, validator
from pydantic import PostgresDsn, field_validator
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
Expand All @@ -11,26 +12,21 @@ class Settings(BaseSettings):

SQLALCHEMY_DATABASE_URI: Optional[PostgresDsn] = None

@validator("SQLALCHEMY_DATABASE_URI", pre=True)
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
@field_validator("SQLALCHEMY_DATABASE_URI", mode="before")
@classmethod
def assemble_db_connection(cls, v: Optional[str], info) -> Any:
if isinstance(v, str):
return v
values = info.data
return PostgresDsn.build(
scheme="postgresql",
user=values.get("POSTGRES_USER"),
username=values.get("POSTGRES_USER"),
password=values.get("POSTGRES_PASSWORD"),
host=values.get("POSTGRES_SERVER"),
path=f"/{values.get('POSTGRES_DB') or ''}",
)

class Config:
case_sensitive = True

# If you want to read environment variables from a .env
# file instead un-comment the below line and create the
# .env file at the root of the project.

# env_file = ".env"
model_config = {"case_sensitive": True, "env_file": ".env"}


settings = Settings()
2 changes: 1 addition & 1 deletion app/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

from ..config import settings

engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI), pool_pre_ping=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Loading