|
| 1 | +# Multi-stage build for optimized image size |
| 2 | +# Stage 1: Build dependencies |
| 3 | +FROM python:3.12-slim AS builder |
| 4 | + |
| 5 | +# Install system dependencies |
| 6 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 7 | + build-essential \ |
| 8 | + curl \ |
| 9 | + && rm -rf /var/lib/apt/lists/* |
| 10 | + |
| 11 | +# Install UV for fast dependency management |
| 12 | +COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv |
| 13 | + |
| 14 | +# Set working directory |
| 15 | +WORKDIR /app |
| 16 | + |
| 17 | +# Copy dependency files |
| 18 | +COPY pyproject.toml README.md ./ |
| 19 | + |
| 20 | +# Install dependencies using UV (much faster than pip) |
| 21 | +# Install just the dependencies, not the package itself yet |
| 22 | +RUN uv pip install --system --no-cache \ |
| 23 | + pandas>=2.3.1 \ |
| 24 | + pyarrow>=20.0.0 \ |
| 25 | + typer>=0.15.2 \ |
| 26 | + adbc-driver-manager>=1.5.0 \ |
| 27 | + adbc-driver-postgresql>=1.5.0 \ |
| 28 | + protobuf>=4.21.0 \ |
| 29 | + base58>=2.1.1 \ |
| 30 | + eth-hash[pysha3]>=0.7.1 \ |
| 31 | + eth-utils>=5.2.0 \ |
| 32 | + google-cloud-bigquery>=3.30.0 \ |
| 33 | + google-cloud-storage>=3.1.0 \ |
| 34 | + arro3-core>=0.5.1 \ |
| 35 | + arro3-compute>=0.5.1 \ |
| 36 | + snowflake-connector-python>=4.0.0 \ |
| 37 | + snowpipe-streaming>=1.0.0 |
| 38 | + |
| 39 | +# Stage 2: Runtime image |
| 40 | +FROM python:3.12-slim |
| 41 | + |
| 42 | +# Install runtime dependencies only |
| 43 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 44 | + libpq5 \ |
| 45 | + && rm -rf /var/lib/apt/lists/* |
| 46 | + |
| 47 | +# Create non-root user for security |
| 48 | +RUN useradd -m -u 1000 amp && \ |
| 49 | + mkdir -p /app /data && \ |
| 50 | + chown -R amp:amp /app /data |
| 51 | + |
| 52 | +# Set working directory |
| 53 | +WORKDIR /app |
| 54 | + |
| 55 | +# Copy Python packages from builder |
| 56 | +COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages |
| 57 | + |
| 58 | +# Copy application code |
| 59 | +COPY --chown=amp:amp src/ ./src/ |
| 60 | +COPY --chown=amp:amp apps/ ./apps/ |
| 61 | +COPY --chown=amp:amp data/ ./data/ |
| 62 | +COPY --chown=amp:amp pyproject.toml ./ |
| 63 | + |
| 64 | +# Switch to non-root user |
| 65 | +USER amp |
| 66 | + |
| 67 | +# Set Python path |
| 68 | +ENV PYTHONPATH=/app |
| 69 | +ENV PYTHONUNBUFFERED=1 |
| 70 | + |
| 71 | +# Health check |
| 72 | +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ |
| 73 | + CMD python -c "import sys; sys.exit(0)" |
| 74 | + |
| 75 | +# Default command - run ERC20 loader |
| 76 | +# Can be overridden with docker run arguments |
| 77 | +ENTRYPOINT ["python", "apps/test_erc20_labeled_parallel.py"] |
| 78 | +CMD ["--blocks", "100000", "--workers", "8", "--flush-interval", "0.5"] |
0 commit comments