# Phase de base
FROM python:3.11-slim AS base

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential libpq-dev gcc libpq5 && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip

COPY src/app/requirements.txt .
RUN python -m venv /venv
ENV PATH="/venv/bin:$PATH"
RUN /venv/bin/pip install --no-cache-dir -r requirements.txt

# Phase finale
FROM python:3.11-slim AS runtime

WORKDIR /app  # 🔴 Ajouté : définit le répertoire de travail

COPY --from=base /venv /venv
ENV PATH="/venv/bin:$PATH"

COPY src/app /app
COPY TpDevOpsProject.md /app/TpDevOpsProject.md

RUN useradd -m -u 1000 devopsuser && chown -R devopsuser:devopsuser /app
USER devopsuser

EXPOSE 8000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--app-dir", "/app"]   