30 lines
685 B
Docker
30 lines
685 B
Docker
# Stage 1: Build
|
|
FROM python:3.12-slim as builder
|
|
|
|
WORKDIR /app
|
|
|
|
COPY pyproject.toml .
|
|
RUN pip install --no-cache-dir poetry && \
|
|
poetry config virtualenvs.create false && \
|
|
poetry install --no-interaction --no-ansi
|
|
|
|
COPY models.py schemas.py main.py test_main.py .
|
|
|
|
# Stage 2: Production
|
|
FROM python:3.12-slim
|
|
|
|
WORKDIR /app
|
|
|
|
COPY --from=builder /root/.local/share/python-poetry/cache /root/.local/share/python-poetry/cache
|
|
COPY --from=builder /app /app
|
|
|
|
RUN useradd -m appuser && \
|
|
chown -R appuser:appuser /app
|
|
|
|
USER appuser
|
|
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
|
|
|
EXPOSE 8000
|
|
|
|
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |