update
This commit is contained in:
parent
3d344b86ac
commit
12eaeb4351
4 changed files with 23 additions and 13 deletions
|
|
@ -25,8 +25,8 @@ RUN mkdir -p /app/data
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
PYTHONDONTWRITEBYTECODE=1
|
PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
# Add healthcheck
|
# Add healthcheck with longer start period for initialization
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
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
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()" || exit 1
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
|
import os
|
||||||
|
|
||||||
from sqlmodel import Session, SQLModel, create_engine # type: ignore
|
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(
|
# Only use check_same_thread for SQLite
|
||||||
DATABASE_URL, echo=True, connect_args={"check_same_thread": False}
|
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():
|
def create_db_and_tables():
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
from fastapi import FastAPI # type: ignore
|
from fastapi import FastAPI # type: ignore
|
||||||
from fastapi.middleware.cors import CORSMiddleware # 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")
|
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(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[
|
allow_origins=cors_origins,
|
||||||
"http://localhost:80",
|
|
||||||
"https://notes.fitzythe.dev",
|
|
||||||
], # Vite dev server
|
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
|
|
@ -33,3 +33,9 @@ app.include_router(tags.router, prefix="/api")
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def root():
|
def root():
|
||||||
return {"message": "Notes API"}
|
return {"message": "Notes API"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health")
|
||||||
|
def health():
|
||||||
|
"""Health check endpoint for Docker and Coolify"""
|
||||||
|
return {"status": "healthy"}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,9 @@ services:
|
||||||
"-c",
|
"-c",
|
||||||
"import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()",
|
"import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()",
|
||||||
]
|
]
|
||||||
interval: 30s
|
interval: 10s
|
||||||
timeout: 10s
|
timeout: 5s
|
||||||
|
start_period: 40s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
ui:
|
ui:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue