# Edge agent image.
#
# Deliberately not slim-with-everything: the framework extras drag in torch,
# which is most of a gigabyte and useless on an edge that only ships data.
# Build with the extras a given site actually needs:
#
#   docker build -f deploy/docker/Dockerfile --build-arg EXTRAS='edge,modbus' -t geo-mlops-edge .
#   docker build -f deploy/docker/Dockerfile --build-arg EXTRAS='edge,gpu,yolo' -t geo-mlops-edge:yolo .

FROM python:3.12-slim AS base

ARG EXTRAS=edge
ENV PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    GEO_EDGE_DATA_DIR=/var/lib/geo-mlops-edge

WORKDIR /app
COPY pyproject.toml README.md ./
COPY src ./src

RUN pip install --upgrade pip \
 && pip install ".[${EXTRAS}]" \
 && rm -rf /root/.cache

# The queue and the model cache must outlive the container; a restart that
# loses two days of buffered data defeats the point of buffering it.
VOLUME ["/var/lib/geo-mlops-edge"]
RUN useradd --system --create-home --home-dir /var/lib/geo-mlops-edge geo-mlops \
 && chown -R geo-mlops:geo-mlops /var/lib/geo-mlops-edge
USER geo-mlops

EXPOSE 8600
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD python -c "import httpx,sys; sys.exit(0 if httpx.get('http://127.0.0.1:8600/health', timeout=3).status_code==200 else 1)"

ENTRYPOINT ["geo-mlops-edge"]
CMD ["run"]
