forked from Rockachopa/Timmy-time-dashboard
78 lines
2.5 KiB
Docker
78 lines
2.5 KiB
Docker
|
|
# ── Timmy Time Dashboard — Multi-stage Optimized Build ─────────────────────
|
||
|
|
#
|
||
|
|
# Multi-stage build for fast, lean image:
|
||
|
|
# 1. builder Install dependencies
|
||
|
|
# 2. runtime Copy only what's needed for production
|
||
|
|
#
|
||
|
|
# Build: docker build -f docker/Dockerfile.dashboard -t timmy-dashboard:latest .
|
||
|
|
# Run: docker run -p 8000:8000 -v timmy-data:/app/data timmy-dashboard:latest
|
||
|
|
|
||
|
|
# ── Stage 1: Builder ──────────────────────────────────────────────────────────
|
||
|
|
FROM python:3.12-slim as builder
|
||
|
|
|
||
|
|
WORKDIR /build
|
||
|
|
|
||
|
|
# Install build dependencies
|
||
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||
|
|
gcc \
|
||
|
|
curl \
|
||
|
|
git \
|
||
|
|
&& rm -rf /var/lib/apt/lists/*
|
||
|
|
|
||
|
|
# Copy only pyproject.toml for dependency caching
|
||
|
|
COPY pyproject.toml .
|
||
|
|
|
||
|
|
# Create minimal package structure
|
||
|
|
RUN mkdir -p src/timmy src/dashboard src/swarm src/infrastructure && \
|
||
|
|
touch src/__init__.py src/timmy/__init__.py src/dashboard/__init__.py \
|
||
|
|
src/swarm/__init__.py src/infrastructure/__init__.py config.py
|
||
|
|
|
||
|
|
# Install Python dependencies (with caching)
|
||
|
|
RUN pip install --no-cache-dir --user -e ".[swarm,telegram]"
|
||
|
|
|
||
|
|
|
||
|
|
# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
|
||
|
|
FROM python:3.12-slim as runtime
|
||
|
|
|
||
|
|
WORKDIR /app
|
||
|
|
|
||
|
|
# Install only runtime dependencies
|
||
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||
|
|
curl \
|
||
|
|
fonts-dejavu-core \
|
||
|
|
&& rm -rf /var/lib/apt/lists/*
|
||
|
|
|
||
|
|
# Copy Python packages from builder
|
||
|
|
COPY --from=builder /root/.local /root/.local
|
||
|
|
|
||
|
|
# Copy application source
|
||
|
|
COPY src/ ./src/
|
||
|
|
COPY static/ ./static/
|
||
|
|
COPY config.py .
|
||
|
|
|
||
|
|
# 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 && \
|
||
|
|
chmod -R o+rX /app/static /app/data
|
||
|
|
|
||
|
|
# 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
|
||
|
|
|
||
|
|
EXPOSE 8000
|
||
|
|
|
||
|
|
# Health check
|
||
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
|
||
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
||
|
|
|
||
|
|
# Run dashboard
|
||
|
|
CMD ["uvicorn", "dashboard.app:app", "--host", "0.0.0.0", "--port", "8000"]
|