# Production container for the agent service. Build:  docker build -t agent-service .
# Run:  docker run -p 8000:8000 -e ANTHROPIC_API_KEY=sk-ant-... -e ENVIRONMENT=production agent-service

FROM python:3.12-slim

# predictable, quiet Python in containers
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
WORKDIR /app

# install dependencies FIRST so this layer is cached when only app code changes
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# run as a non-root user (never run a public service as root)
RUN useradd --create-home appuser
COPY . .
USER appuser

EXPOSE 8000

# the container healthcheck hits the liveness probe; an orchestrator restarts on failure
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
  CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://localhost:8000/healthz').status==200 else 1)"

# multiple workers for concurrency; tune to the number of CPU cores available
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]
