From 12eaeb43517fc568fb49008701bcced43230b734 Mon Sep 17 00:00:00 2001 From: Jamitz Date: Tue, 6 Jan 2026 16:47:18 +0000 Subject: [PATCH] update --- backend/Dockerfile | 4 ++-- backend/app/database.py | 11 +++++++---- backend/app/main.py | 16 +++++++++++----- compose.yaml | 5 +++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 5db4fd5..c365df9 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -25,8 +25,8 @@ RUN mkdir -p /app/data ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 -# Add healthcheck -HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ +# Add healthcheck with longer start period for initialization +HEALTHCHECK --interval=10s --timeout=5s --start-period=40s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()" || exit 1 EXPOSE 8000 diff --git a/backend/app/database.py b/backend/app/database.py index 91bd997..4c15b62 100644 --- a/backend/app/database.py +++ b/backend/app/database.py @@ -1,10 +1,13 @@ +import os + from sqlmodel import Session, SQLModel, create_engine # type: ignore -DATABASE_URL = "sqlite:///./notes.db" +DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./notes.db") -engine = create_engine( - DATABASE_URL, echo=True, connect_args={"check_same_thread": False} -) +# Only use check_same_thread for SQLite +connect_args = {"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {} + +engine = create_engine(DATABASE_URL, echo=True, connect_args=connect_args) def create_db_and_tables(): diff --git a/backend/app/main.py b/backend/app/main.py index 0382638..782c14a 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,3 +1,5 @@ +import os + from fastapi import FastAPI # type: ignore from fastapi.middleware.cors import CORSMiddleware # type:ignore @@ -6,13 +8,11 @@ from app.routes import auth, folders, notes, tags app = FastAPI(title="Notes API") -# CORS - adjust origins for production +# CORS - configure via environment variable +cors_origins = os.getenv("CORS_ORIGINS", "http://localhost:80").split(",") app.add_middleware( CORSMiddleware, - allow_origins=[ - "http://localhost:80", - "https://notes.fitzythe.dev", - ], # Vite dev server + allow_origins=cors_origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], @@ -33,3 +33,9 @@ app.include_router(tags.router, prefix="/api") @app.get("/") def root(): return {"message": "Notes API"} + + +@app.get("/health") +def health(): + """Health check endpoint for Docker and Coolify""" + return {"status": "healthy"} diff --git a/compose.yaml b/compose.yaml index 970dd0b..e96eb79 100644 --- a/compose.yaml +++ b/compose.yaml @@ -21,8 +21,9 @@ services: "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()", ] - interval: 30s - timeout: 10s + interval: 10s + timeout: 5s + start_period: 40s retries: 3 ui: