diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..f48245c053 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,182 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +.vscode +node_modules/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ +postgresus-data/ \ No newline at end of file diff --git a/.env b/.env.example similarity index 97% rename from .env rename to .env.example index 1d44286e25..ed2001bcad 100644 --- a/.env +++ b/.env.example @@ -42,4 +42,4 @@ SENTRY_DSN= # Configure these with your own Docker registry images DOCKER_IMAGE_BACKEND=backend -DOCKER_IMAGE_FRONTEND=frontend +DOCKER_IMAGE_FRONTEND=frontend \ No newline at end of file diff --git a/.gitignore b/.gitignore index a6dd346572..27b1e63b05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,182 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + .vscode node_modules/ /test-results/ /playwright-report/ /blob-report/ /playwright/.cache/ +postgresus-data/ \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index fc672e525f..5e4f0e2d3b 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10 +FROM python:3.11.8-slim ENV PYTHONUNBUFFERED=1 diff --git a/backend/app/api/routes/utils.py b/backend/app/api/routes/utils.py index fc093419b3..9d1791e181 100644 --- a/backend/app/api/routes/utils.py +++ b/backend/app/api/routes/utils.py @@ -1,11 +1,12 @@ -from fastapi import APIRouter, Depends +from fastapi import APIRouter, Depends, status +from fastapi.responses import JSONResponse from pydantic.networks import EmailStr from app.api.deps import get_current_active_superuser from app.models import Message from app.utils import generate_test_email, send_email -router = APIRouter(prefix="/utils", tags=["utils"]) +router = APIRouter(prefix="", tags=["utils"]) @router.post( @@ -25,7 +26,16 @@ def test_email(email_to: EmailStr) -> Message: ) return Message(message="Test email sent") +@router.get("/health-check", response_class=JSONResponse, status_code=status.HTTP_200_OK, tags=["Health"]) +async def health_check(): + """ + Health check endpoint to verify that the service is running. + + Returns: + JSONResponse: {"status": "ok"} + """ + return {"status": "ok"} -@router.get("/health-check/") -async def health_check() -> bool: - return True +@router.get("/sentry-debug", tags=["Debug"]) +async def trigger_error(): + division_by_zero = 1 / 0 diff --git a/backend/app/core/config.py b/backend/app/core/config.py index 650b9f7910..abc7211ea0 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -1,5 +1,6 @@ import secrets import warnings +from pathlib import Path from typing import Annotated, Any, Literal from pydantic import ( @@ -15,6 +16,8 @@ from typing_extensions import Self +BASE_DIR = Path(__file__).resolve().parents[3] + def parse_cors(v: Any) -> list[str] | str: if isinstance(v, str) and not v.startswith("["): return [i.strip() for i in v.split(",") if i.strip()] @@ -25,12 +28,11 @@ def parse_cors(v: Any) -> list[str] | str: class Settings(BaseSettings): model_config = SettingsConfigDict( - # Use top level .env file (one level above ./backend/) - env_file="../.env", + env_file=BASE_DIR / ".env", env_ignore_empty=True, extra="ignore", ) - API_V1_STR: str = "/api/v1" + API_V1_STR: str = "" SECRET_KEY: str = secrets.token_urlsafe(32) # 60 minutes * 24 hours * 8 days = 8 days ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 @@ -49,7 +51,7 @@ def all_cors_origins(self) -> list[str]: ] PROJECT_NAME: str - SENTRY_DSN: HttpUrl | None = None + SENTRY_DSN: str | None = None POSTGRES_SERVER: str POSTGRES_PORT: int = 5432 POSTGRES_USER: str diff --git a/backend/app/main.py b/backend/app/main.py index 9a95801e74..f7d083d519 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,7 +1,9 @@ -import sentry_sdk from fastapi import FastAPI from fastapi.routing import APIRoute from starlette.middleware.cors import CORSMiddleware +import sentry_sdk +from sentry_sdk.integrations.fastapi import FastApiIntegration +from sentry_sdk.integrations.logging import LoggingIntegration from app.api.main import api_router from app.core.config import settings @@ -12,7 +14,19 @@ def custom_generate_unique_id(route: APIRoute) -> str: if settings.SENTRY_DSN and settings.ENVIRONMENT != "local": - sentry_sdk.init(dsn=str(settings.SENTRY_DSN), enable_tracing=True) + sentry_sdk.init( + dsn=settings.SENTRY_DSN, + environment=settings.ENVIRONMENT, + integrations=[ + FastApiIntegration(), + LoggingIntegration( + level=None, # Capture all logs + event_level="ERROR" # Send errors as Sentry events + ), + ], + traces_sample_rate=1.0, # Adjust in production (e.g., 0.1) + send_default_pii=True, + ) app = FastAPI( title=settings.PROJECT_NAME, diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 0751abe901..87007f2d24 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -6,7 +6,7 @@ services: # etc. To enable it, update .env, set: # DOMAIN=localhost.tiangolo.com proxy: - image: traefik:3.0 + image: traefik volumes: - /var/run/docker.sock:/var/run/docker.sock ports: diff --git a/docker-compose.yml b/docker-compose.yml index b1aa17ed43..68a57625b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: db: - image: postgres:17 + image: postgres:17-alpine restart: always healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] @@ -162,6 +162,15 @@ services: # Enable redirection for HTTP and HTTPS - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.middlewares=https-redirect + + postgresus: + image: rostislavdugin/postgresus:latest + ports: + - "4005:4005" + volumes: + - ./postgresus-data:/postgresus-data + restart: unless-stopped + volumes: app-db-data: