# Image for the Barg Sabz mock API and the email assistant (lesson OPS-250-L02). Synthetic data only.
# Build context = this folder, containing: Dockerfile, compose.yaml, barg-sabz-mock-api.py, email_assistant.py
#
# In production pin the base image by digest (tags are mutable), e.g. python:3.12-slim@sha256:<digest>;
# see the digest with:  docker image inspect --format '{{index .RepoDigests 0}}' python:3.12-slim
FROM python:3.12-slim

WORKDIR /app
# Only the two scripts; .dockerignore keeps everything else (secrets, data, .git) out of the build context.
COPY barg-sabz-mock-api.py email_assistant.py ./

# A data folder the unprivileged user can write to. A new named volume mounted at /data copies this
# folder's ownership; without it, the volume is owned by root and the app gets "unable to open database file".
RUN mkdir -p /data && chown 10001:10001 /data

# Run as an unprivileged numeric user (no root inside the container).
USER 10001

EXPOSE 8787
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
  CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8787/health', timeout=2)"]

# Default command: the mock API. compose.yaml overrides it for the assistant job.
CMD ["python", "barg-sabz-mock-api.py", "--host", "0.0.0.0", "--port", "8787"]
