# Reference image for the OpenSmartRoute control plane (`osr serve`).
# Build:  docker build -t opensmartroute:0.5.0 -f deploy/Dockerfile .
# Run:    docker run -p 8000:8000 -v $PWD/examples:/config opensmartroute:0.5.0
FROM python:3.12-slim AS build
WORKDIR /src
COPY pyproject.toml README.md LICENSE ./
COPY src ./src
RUN pip install --no-cache-dir --prefix=/install ".[yaml,server,fast]"

FROM python:3.12-slim
LABEL org.opencontainers.image.title="OpenSmartRoute" \
      org.opencontainers.image.source="https://github.com/isathish/OpenSmartRoute" \
      org.opencontainers.image.licenses="Apache-2.0"
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 \
    OSR_TARGETS=/config/targets.yaml OSR_RULES= OSR_STATE=/state OSR_MODELS= OSR_SLM= \
    OSR_LLM_BASE_URL= OSR_LLM_MODEL= \
    OSR_AUTOPILOT= OSR_AUTOPILOT_ARGS= OSR_CACHE_DIR= OSR_CATALOGUE= \
    OSR_HOST=0.0.0.0 OSR_PORT=8000
COPY --from=build /install /usr/local
COPY deploy/entrypoint.sh /entrypoint.sh
RUN useradd --uid 10001 --no-create-home osr && mkdir -p /state /config && chown -R osr /state && chmod +x /entrypoint.sh
USER 10001
VOLUME ["/state"]
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s CMD python -c "import urllib.request,os;urllib.request.urlopen(f'http://127.0.0.1:{os.environ[\"OSR_PORT\"]}/healthz')" || exit 1
ENTRYPOINT ["/entrypoint.sh"]
