FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    TZ=Europe/Paris

# tzdata fournit les fuseaux horaires utilisés par les rappels.
RUN apt-get update && apt-get full-upgrade -y \
    && apt-get install -y --no-install-recommends tzdata nano \
    && rm -rf /var/lib/apt/lists/* \
    && groupadd --gid 1000 candipilot \
    && useradd --uid 1000 --gid candipilot --no-create-home candipilot \
    && mkdir -p /opt/candipilot /data \
    && chown candipilot:candipilot /data

# Placer ap.py et favicon.png dans le même dossier que ce Dockerfile.
COPY ap.py favicon.png /opt/candipilot/

# Le répertoire courant accueille la base SQLite et la favicon locale.
# La favicon est copiée au démarrage pour fonctionner avec un volume neuf.
WORKDIR /data
USER candipilot
EXPOSE 8000
CMD ["sh", "-c", "cp /opt/candipilot/favicon.png /data/favicon.png && exec python /opt/candipilot/ap.py"]
