Files
foxhunt/services/trading_service/Dockerfile
jgrusewski 86f7f1fa76 fix: comprehensive audit — real brokers, deployment fixes, production safety
Codebase audit identified 23 findings across 4 dimensions (production safety,
code health, deployment readiness, test quality). This commit fixes all of them.

Broker execution layer (was entirely stubbed):
- Real IBKR TWS client via ibapi crate (950+ lines, feature-gated)
- ICMarkets ctrader-openapi now always-on (removed feature flag)
- Real broker routing with health monitoring and exponential backoff reconnect
- Validated against live IB Gateway Docker (6/6 connectivity tests pass)

Deployment blockers:
- Fixed 6 broken Dockerfiles (removed COPY foxhunt-deploy)
- Created foxhunt K8s namespace, secret templates, migration job
- Added liveness probes to all 7 K8s services
- IB Gateway manifest (ghcr.io/gnzsnz/ib-gateway:stable)
- IBKR credentials in Scaleway Secret Manager via Terragrunt
- Fixed port collisions and mismatches across services

Production safety (9 critical + 6 high/medium fixes):
- Asset-class-specific VaR volatility (not flat 2%)
- Real parametric VaR with z-score 95th percentile
- Kyle's lambda regression (100-bar rolling window)
- Per-feature running statistics from historical data
- VWAP-based slippage reference, regime duration tracking
- Real Databento JSON parsing for OHLCV/Trade/Quote

Code health:
- Removed #![allow(dead_code)] from ml, data, config
- Fixed log:: → tracing:: in 4 production files
- Removed dead workspace deps (ratatui, crossterm)

Verified: cargo check --workspace (0 errors), trading_engine 330 tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 00:32:10 +01:00

113 lines
3.5 KiB
Docker

# Multi-stage build for Foxhunt Trading Service
# Wave 71 Agent 8: Production-optimized Docker image
# =============================================================================
# Builder Stage
# =============================================================================
FROM rust:1.89-slim-bookworm AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
protobuf-compiler \
perl \
make \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /build
# Set CUDA environment variables to skip GPU detection during build
# CUDA 13.0 matches development environment, RTX 3050 Ti = compute capability 8.6
ENV CUDARC_CUDA_VERSION=13000
ENV CUDA_COMPUTE_CAP=86
# Copy workspace manifests
COPY Cargo.toml Cargo.lock ./
# Copy sqlx offline cache for compile-time query verification
COPY .sqlx ./.sqlx
# Copy workspace members to satisfy manifest dependencies
COPY trading_engine ./trading_engine
COPY risk ./risk
COPY risk-data ./risk-data
COPY trading-data ./trading-data
COPY fxt ./fxt
COPY ml ./ml
COPY ml-data ./ml-data
COPY data ./data
COPY backtesting ./backtesting
COPY adaptive-strategy ./adaptive-strategy
COPY common ./common
COPY storage ./storage
COPY model_loader ./model_loader
COPY market-data ./market-data
COPY database ./database
COPY config ./config
COPY web-gateway ./web-gateway
COPY ctrader-openapi ./ctrader-openapi
COPY services/backtesting_service ./services/backtesting_service
COPY services/broker_gateway_service ./services/broker_gateway_service
COPY services/trading_service ./services/trading_service
COPY services/ml_training_service ./services/ml_training_service
COPY services/data_acquisition_service ./services/data_acquisition_service
COPY services/trading_agent_service ./services/trading_agent_service
COPY services/api_gateway ./services/api_gateway
COPY services/load_tests ./services/load_tests
COPY services/stress_tests ./services/stress_tests
COPY services/integration_tests ./services/integration_tests
COPY tests ./tests
# Enable sqlx offline mode to use cached query metadata
ENV SQLX_OFFLINE=true
# Build the application
RUN cargo build --release -p trading_service
# =============================================================================
# Runtime Stage
# =============================================================================
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Download and install grpc_health_probe
RUN curl -sSL https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.25/grpc_health_probe-linux-amd64 \
-o /usr/local/bin/grpc_health_probe && \
chmod +x /usr/local/bin/grpc_health_probe
# Create non-root user
RUN groupadd --system --gid 1000 foxhunt && \
useradd --system --uid 1000 --gid foxhunt --shell /bin/bash foxhunt
# Create application directories
RUN mkdir -p /app/config /app/logs /app/data && \
chown -R foxhunt:foxhunt /app
# Set working directory
WORKDIR /app
# Copy binary from builder
COPY --from=builder /build/target/release/trading_service ./trading_service
RUN chmod +x ./trading_service
# Switch to non-root user
USER foxhunt
# Expose gRPC and metrics ports
EXPOSE 50051 9092
# Health check using grpc_health_probe
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=3 \
CMD /usr/local/bin/grpc_health_probe -addr=localhost:50051 || exit 1
# Run the application
ENTRYPOINT ["./trading_service"]