Spaces:
Running
Running
File size: 3,058 Bytes
80d13c9 7e97061 80d13c9 4c79e2a f64b002 b3b36f7 f64b002 b3b36f7 f64b002 af56320 7e97061 af56320 7e97061 80d13c9 7e97061 80d13c9 b3b36f7 f64b002 af56320 b3b36f7 f64b002 2c56f6b b3b36f7 1a2d1b3 db6c149 f64b002 8d37fa0 b3b36f7 1e6ab4d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | # =============================================================================
# Stage 1: Build Native Rust PyO3 Wheel (copper_rust_accel)
# =============================================================================
FROM python:3.11-slim@sha256:9a7765b36773a37061455b332f18e265e7f58f6fea9c419a550d2a8b0e9db834 AS rust-builder
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
gcc \
libc6-dev \
&& curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal \
&& pip install --no-cache-dir maturin \
&& rm -rf /var/lib/apt/lists/*
ENV PATH="/root/.cargo/bin:${PATH}"
COPY ./rust_accel /build/rust_accel
RUN cd /build/rust_accel && maturin build --release -i python3 --out /wheels
# =============================================================================
# Stage 2: Lean Production Runtime Image (Zero Rust Toolchain Bloat)
# =============================================================================
FROM python:3.11-slim@sha256:9a7765b36773a37061455b332f18e265e7f58f6fea9c419a550d2a8b0e9db834
WORKDIR /code
# OS deps: redis-server + supervisor + build tools
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
redis-server \
supervisor \
curl \
&& rm -rf /var/lib/apt/lists/*
# Environment
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PYTHONPATH=/code \
REDIS_URL=redis://127.0.0.1:6379/0 \
HF_HOME=/data/hf_cache \
HF_HUB_ENABLE_HF_TRANSFER=1 \
HF_HUB_DISABLE_PROGRESS_BARS=1 \
TRANSFORMERS_VERBOSITY=error \
TRANSFORMERS_NO_ADVISORY_WARNINGS=1 \
TOKENIZERS_PARALLELISM=false
# Install compiled Rust PyO3 wheel from builder stage (~250 KB) + Rust hf_transfer
COPY --from=rust-builder /wheels /wheels
RUN pip install --no-cache-dir /wheels/*.whl hf_transfer && rm -rf /wheels
# Python deps
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# Pre-cache ProsusAI/finbert weights in image layer to eliminate cold-start download on HF Space
RUN python -c "from transformers import AutoTokenizer, AutoModelForSequenceClassification; AutoTokenizer.from_pretrained('ProsusAI/finbert'); AutoModelForSequenceClassification.from_pretrained('ProsusAI/finbert')" || true; \
mkdir -p /data/hf_cache && chmod -R a+rwX /data/hf_cache
# App code
COPY ./app /code/app
COPY ./config /code/config
COPY ./adapters /code/adapters
COPY ./worker /code/worker
COPY ./pipelines /code/pipelines
COPY ./migrations /code/migrations
COPY ./deep_learning /code/deep_learning
COPY ./backtest /code/backtest
# Copy pre-trained model files (from Kaggle)
COPY ./data/models /data/models
# Supervisor config
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# HF Spaces default port: 7860
EXPOSE 7860
# Run supervisord (manages redis + api + worker)
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|