# Linux AMD64 runtime; the release archive supplies the already-built UI.
FROM python:3.12-slim-bookworm
WORKDIR /app
COPY requirements.lock ./
RUN pip install --no-cache-dir -r requirements.lock
COPY backend ./backend
COPY frontend/dist ./frontend/dist
COPY docker_start.py /app/docker_start.py
COPY nas_update.py /app/nas_update.py
COPY Dockerfile /app/Dockerfile
# NAS ZIP extraction can leave copied code readable only by root (0600/0700).
# Normalize only application files inside the image, before dropping privileges.
RUN find /app -type d -exec chmod 0755 {} + \
    && find /app -type f -exec chmod 0644 {} + \
    && useradd --system --uid 10001 watt-e-pilot \
    && mkdir /data && chown 10001 /data && chmod 0750 /data
USER 10001
ENV PYTHONPATH=/app/backend \
    WATT_E_PILOT_DATA_DIR=/data \
    WATT_E_PILOT_LAN=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1
EXPOSE 8090
RUN python /app/docker_start.py --check
ENTRYPOINT ["python", "/app/docker_start.py"]
CMD []
