FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY app.py katalog.py krankenkassen.py changelog.py start.py ./
COPY db/schema.sql db/schema.sql
COPY templates/ templates/

RUN useradd -m -u 1000 pflegepilot \
    && mkdir -p db static/fotos static/briefe static/dokumente static/logo \
    && chown -R pflegepilot:pflegepilot /app

USER pflegepilot

EXPOSE 5050

# init_db() ist idempotent (siehe app.py) - unbedenklich bei jedem Containerstart erneut auszufuehren
CMD ["sh", "-c", "python -c 'from app import init_db; init_db()' && exec gunicorn --bind 0.0.0.0:5050 --workers ${GUNICORN_WORKERS:-2} --timeout 120 app:app"]
