# Django owner-portal instance. One Python process (gunicorn) serving the app and
# its own static assets via WhiteNoise. Postgres is a compose sidecar.
FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    DJANGO_SETTINGS_MODULE=config.settings

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .

# Collect static at build (no DB needed). SECRET_KEY uses the dev fallback here;
# the real key is injected at runtime from .app.env.
RUN python manage.py collectstatic --noinput

EXPOSE 8000

# Migrate, create the admin on first boot (idempotent — fails silently if it
# already exists), then serve.
CMD ["sh", "-c", "python manage.py migrate --noinput && (python manage.py createsuperuser --noinput 2>/dev/null || true) && exec gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 3 --timeout 60"]
