From 0ec97bd2bb3cb9c5366d0bdb94e7280ff6daa8e9 Mon Sep 17 00:00:00 2001 From: k-candidate Date: Mon, 10 Aug 2026 17:49:05 +0200 Subject: [PATCH] feat: distroless python docker image --- .dockerignore | 9 +++++++++ Dockerfile | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5d96af5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.mypy_cache +.pytest_cache +.ruff_cache +.venv +__pycache__ +*.py[cod] +build +dist diff --git a/Dockerfile b/Dockerfile index 474798a..2d03f80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.14-slim +FROM python:3.14-slim AS builder WORKDIR /app @@ -9,13 +9,21 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv COPY pyproject.toml uv.lock ./ # Install dependencies -RUN uv sync --frozen --no-install-project --no-dev +RUN uv sync --frozen --no-install-project --no-dev --compile-bytecode # Copy source code COPY . . # Install the project itself -RUN uv sync --frozen --no-dev +RUN uv sync --frozen --no-dev --compile-bytecode + +FROM nvcr.io/nvidia/distroless/python:3.14-v4.0.10 + +WORKDIR /app +ENV PATH="/app/.venv/bin:${PATH}" \ + PYTHONUNBUFFERED=1 + +COPY --from=builder /app /app EXPOSE 8000 -CMD ["uv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] +CMD ["/app/.venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]