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

EXPOSE 5005

CMD ["gunicorn", "-b", "0.0.0.0:5005", "-w", "4", "app:app"]
