forked from cleveragents/cleveragents-core
927c5a4681
Reorder COPY and RUN instructions in both Dockerfile and Dockerfile.server to leverage Docker's layer caching for the dependency installation step. Previously, pyproject.toml, README.md, and src/ were all copied together before running uv pip install, meaning any source code change would invalidate the dependency layer cache and force a full reinstall. The new pattern copies only the dependency manifests (pyproject.toml and uv.lock) first, installs the build tool in a cached layer, then copies README.md and src/ for the actual wheel build. This ensures the uv pip install step is only re-executed when pyproject.toml or uv.lock change, not on every source code change. ISSUES CLOSED: #1667
49 lines
1.2 KiB
Docker
49 lines
1.2 KiB
Docker
# syntax=docker/dockerfile:1
|
|
FROM python:3.13-slim AS builder
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install uv
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
|
|
|
# Set up working directory
|
|
WORKDIR /app
|
|
|
|
# Copy dependency manifests first to leverage Docker layer caching.
|
|
# The expensive dependency installation step is only re-executed when
|
|
# pyproject.toml or uv.lock change, not on every source code change.
|
|
COPY pyproject.toml uv.lock ./
|
|
|
|
# Install build tool — this layer is cached as long as pyproject.toml
|
|
# and uv.lock remain unchanged.
|
|
RUN uv pip install --system build
|
|
|
|
# Copy remaining source files needed for the wheel build.
|
|
COPY README.md ./
|
|
COPY src/ ./src/
|
|
|
|
# Build wheel
|
|
RUN python -m build --wheel --outdir /dist
|
|
|
|
# Runtime stage
|
|
FROM python:3.13-slim
|
|
|
|
# Create non-root user
|
|
RUN useradd -m -u 1000 appuser
|
|
|
|
# Install runtime dependencies
|
|
COPY --from=builder /dist/*.whl /tmp/
|
|
RUN pip install --no-cache-dir /tmp/*.whl && \
|
|
rm -rf /tmp/*
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
WORKDIR /app
|
|
|
|
# Set entrypoint
|
|
ENTRYPOINT ["python", "-m", "cleveragents"]
|
|
CMD ["--help"]
|