FROM python:3.13-slim

WORKDIR /app

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

COPY . .

RUN addgroup --system --gid 1000 app && \
    adduser --system --uid 1000 --ingroup app --disabled-password --disabled-login --no-create-home app && \
    chown -R app:app /app && chmod -R u+w /app && \
    find / -perm /4000 -o -perm /2000 2>/dev/null | xargs -r chmod ug-s

USER app
ENV HOME=/tmp
# Ohne das puffert Python stdout blockweise, weil es kein Terminal ist -
# die print()-Ausgaben der App tauchen dann nicht in "docker compose logs" auf.
ENV PYTHONUNBUFFERED=1

EXPOSE 5005

# --access-logfile - schreibt jeden Request nach stdout. Ohne das protokolliert
# gunicorn keine Zugriffe, und man sieht nicht, ob eine Anfrage ueberhaupt ankommt.
CMD ["gunicorn", "-b", "0.0.0.0:5005", "-w", "4", "--access-logfile", "-", "app:app"]
