|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +########## BUILD STAGE ########## |
| 4 | +FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS build |
| 5 | + |
| 6 | +# We'll treat /app as the project root inside the container |
| 7 | +WORKDIR /app |
| 8 | + |
| 9 | +# Copy dependency metadata from your repo |
| 10 | +# (pyproject.toml lives at app/applications/pyproject.toml on host) |
| 11 | +COPY applications/pyproject.toml ./pyproject.toml |
| 12 | +COPY applications/uv.lock ./uv.lock |
| 13 | +# If you have a uv.lock, keep this; otherwise delete/comment it |
| 14 | +# COPY app/applications/uv.lock ./uv.lock |
| 15 | + |
| 16 | +ENV UV_COMPILE_BYTECODE=1 \ |
| 17 | + UV_LINK_MODE=copy |
| 18 | + |
| 19 | +# Install all dependencies (including uvicorn) into /app/.venv |
| 20 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 21 | + uv sync --frozen --no-dev |
| 22 | + |
| 23 | +# Now bring in the actual source code |
| 24 | +# applications package (where backend.py lives) |
| 25 | +COPY applications ./applications |
| 26 | +# agents directory (no __init__.py needed) |
| 27 | +COPY agents ./agents |
| 28 | + |
| 29 | + |
| 30 | +########## RUNTIME STAGE ########## |
| 31 | +FROM python:3.12-slim AS runtime |
| 32 | + |
| 33 | +WORKDIR /app |
| 34 | + |
| 35 | +# Ensure we use the venv's python + scripts (uvicorn, etc.) |
| 36 | +ENV PATH="/app/.venv/bin:$PATH" \ |
| 37 | + PYTHONUNBUFFERED=1 \ |
| 38 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 39 | + # let Python see /app so "import agents" works |
| 40 | + PYTHONPATH="/app" |
| 41 | + |
| 42 | +# Copy the venv and source code from build stage |
| 43 | +COPY --from=build /app /app |
| 44 | + |
| 45 | +# Sanity: this should run backend.py exactly like: |
| 46 | +# uv run applications/backend.py |
| 47 | +# but using the venv python directly |
| 48 | +CMD ["python", "applications/backend.py"] |
0 commit comments