# Replace with the company internal Python base image in deployment.
FROM registry.company.com/python:{{ lang_version }} AS builder

WORKDIR /app
COPY pyproject.toml requirements.txt ./
RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir -r requirements.txt

COPY . .
RUN pip install --no-cache-dir --no-deps .

FROM registry.company.com/python:{{ lang_version }}
RUN useradd -m -u 1000 appuser
USER appuser
WORKDIR /app
COPY --from=builder --chown=appuser:appuser /app /app

EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
  CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health/live', timeout=2)" || exit 1
CMD ["uvicorn", "{{ package_name }}.main:app", "--host", "0.0.0.0", "--port", "8000"]
