# Bags to Door (magazinul online al fabricii Electric SRL) - aplicație Django
# Panoul serverului citește: dependențele de sistem (apt), requirements.txt și comenzile de pornire din CMD.
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    BTD_DATA_DIR=/app/data \
    BTD_MEDIA_DIR=/app/media

# Pillow are bibliotecile incluse; tzdata pentru ora României (termene de livrare, ora limită de expediere)
RUN apt-get update && apt-get install -y --no-install-recommends tzdata && rm -rf /var/lib/apt/lists/*
ENV TZ=Europe/Bucharest

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

EXPOSE 8000

# La fiecare pornire: migrări, import inițial (doar dacă baza e goală), fișiere statice,
# planificatorul (coșuri abandonate, WinMENTOR, curs BNR, cereri de recenzie) în fundal, apoi serverul web.
CMD ["sh", "-c", "python manage.py migrate --noinput && python manage.py seed_catalog --if-empty && python manage.py import_blog && python manage.py import_descriptions && python manage.py import_category_content && python manage.py ensure_admin && python manage.py collectstatic --noinput && (python manage.py run_scheduler &) && gunicorn config.wsgi:application --bind 0.0.0.0:${PORT:-8000} --workers 3 --timeout 60 --access-logfile -"]
