diff --git a/Dockerfile b/Dockerfile index 37a1eae..3de9f8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,40 @@ -FROM python:3.11-slim +# ── Stage 1: build ─────────────────────────────────────────────────────────── +# Compiles native extensions (ckzg, asyncpg, cryptography) so the final image +# only carries the compiled .so files, not the build toolchain. +FROM python:3.11-slim AS builder -# System deps needed for native extensions: -# gcc, libpq-dev → asyncpg (Postgres driver) -# libffi-dev → cryptography -# build-essential → general C compilation fallback -# curl → healthcheck probe RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc build-essential libpq-dev libffi-dev curl \ + gcc build-essential cmake libpq-dev libffi-dev \ && rm -rf /var/lib/apt/lists/* -WORKDIR /app +WORKDIR /build -# Upgrade pip + install wheel first so pre-built wheels are preferred RUN pip install --no-cache-dir --upgrade pip wheel setuptools -# Install Python deps (separate layer for cache efficiency) COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install --no-cache-dir --prefix=/install -r requirements.txt -# App source + +# ── Stage 2: runtime ───────────────────────────────────────────────────────── +FROM python:3.11-slim + +# Only runtime shared libs needed (libpq for asyncpg, libgomp for numpy if used) +RUN apt-get update && apt-get install -y --no-install-recommends \ + libpq5 curl \ + && rm -rf /var/lib/apt/lists/* + +# Copy compiled packages from builder +COPY --from=builder /install /usr/local + +WORKDIR /app COPY . . -# Make entrypoint executable RUN chmod +x entrypoint.sh -# Non-root user for security +# Non-root user RUN useradd -m appuser && chown -R appuser /app USER appuser EXPOSE 8000 -# Runs: alembic upgrade head → uvicorn ENTRYPOINT ["./entrypoint.sh"] diff --git a/requirements.txt b/requirements.txt index 2c9a9a6..d7e8c44 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,18 @@ -fastapi==0.111.0 -uvicorn[standard]==0.29.0 -sqlalchemy[asyncio]==2.0.30 -aiosqlite==0.20.0 -asyncpg==0.29.0 -alembic==1.13.1 -pydantic==2.7.1 -pydantic-settings==2.2.1 -httpx==0.27.0 -feedparser==6.0.11 -websockets==12.0 -anthropic==0.28.0 -hyperliquid-python-sdk==0.8.0 -eth-account==0.11.0 -redis==5.0.4 -apscheduler==3.10.4 -python-dotenv==1.0.1 -cryptography==42.0.8 +fastapi==0.128.8 +uvicorn[standard]==0.39.0 +sqlalchemy[asyncio]==2.0.49 +aiosqlite==0.22.1 +asyncpg==0.31.0 +alembic==1.16.5 +pydantic==2.13.2 +pydantic-settings==2.11.0 +httpx==0.28.1 +feedparser==6.0.12 +websockets==15.0.1 +anthropic==0.96.0 +hyperliquid-python-sdk==0.23.0 +eth-account==0.13.7 +redis==7.0.1 +apscheduler==3.11.2 +python-dotenv==1.2.1 +cryptography==46.0.7