2026-02-28 11:07:19 -05:00
|
|
|
# ── Timmy Agent — Multi-stage Optimized Build ────────────────────────────────
|
|
|
|
|
#
|
|
|
|
|
# Lightweight agent container for running Timmy or swarm workers.
|
|
|
|
|
#
|
|
|
|
|
# Build: docker build -f docker/Dockerfile.agent -t timmy-agent:latest .
|
|
|
|
|
# Run: docker run -e COORDINATOR_URL=http://dashboard:8000 timmy-agent:latest
|
|
|
|
|
|
|
|
|
|
# ── Stage 1: Builder ──────────────────────────────────────────────────────────
|
2026-02-28 13:12:14 -05:00
|
|
|
FROM python:3.12-slim AS builder
|
2026-02-28 11:07:19 -05:00
|
|
|
|
|
|
|
|
WORKDIR /build
|
|
|
|
|
|
|
|
|
|
# Install build dependencies
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
2026-02-28 13:12:14 -05:00
|
|
|
gcc curl \
|
2026-02-28 11:07:19 -05:00
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
2026-02-28 13:12:14 -05:00
|
|
|
# Install Poetry + export plugin for dependency export
|
|
|
|
|
RUN pip install --no-cache-dir poetry poetry-plugin-export
|
|
|
|
|
|
|
|
|
|
# Copy only dependency files for layer caching
|
|
|
|
|
COPY pyproject.toml poetry.lock ./
|
2026-02-28 11:07:19 -05:00
|
|
|
|
2026-02-28 13:12:14 -05:00
|
|
|
# Export pinned requirements and install with pip
|
|
|
|
|
RUN poetry export --extras swarm --without-hashes \
|
|
|
|
|
-f requirements.txt -o requirements.txt
|
2026-02-28 11:07:19 -05:00
|
|
|
|
2026-02-28 13:12:14 -05:00
|
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
|
|
|
pip install --no-cache-dir --user -r requirements.txt
|
2026-02-28 11:07:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
|
2026-02-28 13:12:14 -05:00
|
|
|
FROM python:3.12-slim AS runtime
|
2026-02-28 11:07:19 -05:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Install only runtime dependencies
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
|
curl \
|
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
# Copy Python packages from builder
|
|
|
|
|
COPY --from=builder /root/.local /root/.local
|
|
|
|
|
|
|
|
|
|
# Copy application source
|
|
|
|
|
COPY src/ ./src/
|
|
|
|
|
|
|
|
|
|
# Create data directory
|
|
|
|
|
RUN mkdir -p /app/data
|
|
|
|
|
|
|
|
|
|
# Create non-root user
|
|
|
|
|
RUN groupadd -r timmy && useradd -r -g timmy -d /app -s /sbin/nologin timmy && \
|
|
|
|
|
chown -R timmy:timmy /app
|
|
|
|
|
|
|
|
|
|
# Set environment
|
|
|
|
|
ENV PATH=/root/.local/bin:$PATH
|
|
|
|
|
ENV PYTHONPATH=/app/src
|
|
|
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
|
|
|
|
|
|
|
|
# Switch to non-root user
|
|
|
|
|
USER timmy
|
|
|
|
|
|
|
|
|
|
# Default: run Timmy agent (can be overridden)
|
|
|
|
|
CMD ["python", "-m", "timmy.docker_agent"]
|