FROM python:3.10-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY requirements.txt /app/
RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt

COPY . /app/

# Statische Dateien nach /srv/static (ausserhalb von /app, das per Bind-Mount überlagert wird)
RUN CLOUDMON_DATA_DIR=/tmp/build-data python manage.py collectstatic --noinput && rm -rf /tmp/build-data

# /data: SQLite (Benutzer, Audit-Log) + Secret Key – als Volume mounten
VOLUME ["/data"]
EXPOSE 8000

# Beim Start DB-Schema aktualisieren, dann Gunicorn
CMD ["sh", "-c", "python manage.py migrate --noinput && exec gunicorn core.wsgi:application --bind 0.0.0.0:8000 --workers 2 --timeout 60"]
