-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (46 loc) · 1.7 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Production-ready Dockerfile for uv-based Python project (no dev deps in final image)
# - Locks deps inside the build (deterministic)
# - Installs only runtime deps in final image
# - Runs as non-root
# - Small final image (python:3.12-slim)
# ---------- Base image (common) ----------
FROM python:3.12-slim AS base
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PYTHONOPTIMIZE=2
# Install system deps if needed (kept minimal)
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# ---------- Builder: uv + lock + install (no dev) ----------
FROM base AS builder
# Bring in uv binary
COPY --from=ghcr.io/astral-sh/uv:0.8.13 /uv /usr/local/bin/uv
WORKDIR /app
# Copy project metadata first for layer caching
COPY pyproject.toml /app/
# Create or refresh lock deterministically for Python 3.12
# (Respects [tool.uv] python = "3.12")
RUN --mount=type=cache,target=/root/.cache/uv \
uv lock
# Install ONLY runtime deps into a local venv (no project yet, and no dev deps)
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev
# Now copy the source and install the project into the same venv
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
# ---------- Final runtime image ----------
FROM base AS runtime
WORKDIR /app
# Create a non-root user
RUN useradd -m -u 10001 appuser
# Copy the entire app (including .venv from builder)
COPY --from=builder /app /app
# Put venv on PATH
ENV PATH="/app/.venv/bin:${PATH}"
USER appuser
EXPOSE 8000
# Default command: run the CLI entry point
CMD ["uv", "run", "agent-starter"]