# ============================================================================= # FOXHUNT BACKTESTING SERVICE - CLOUD-NATIVE PRODUCTION CONTAINER # ============================================================================= # This Dockerfile creates a balanced performance container for the Backtesting Service # optimized for cloud-native deployment with service mesh compatibility # ============================================================================= # BUILDER STAGE - Optimized Build # ============================================================================= FROM rust:1.83-slim as backtesting-builder # Install build dependencies RUN apt-get update && apt-get install -y \ build-essential \ pkg-config \ libssl-dev \ ca-certificates \ libpq-dev \ protobuf-compiler \ && rm -rf /var/lib/apt/lists/* # Production Cargo configuration ENV CARGO_NET_GIT_FETCH_WITH_CLI=true ENV CARGO_INCREMENTAL=0 ENV CARGO_PROFILE_RELEASE_LTO=true ENV CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 ENV CARGO_PROFILE_RELEASE_OPT_LEVEL=3 ENV CARGO_PROFILE_RELEASE_DEBUG=false ENV CARGO_PROFILE_RELEASE_STRIP=true WORKDIR /workspace # Copy workspace files for backtesting COPY Cargo.toml Cargo.lock ./ COPY trading_engine ./trading_engine COPY risk ./risk COPY ml ./ml COPY data ./data COPY risk-data ./risk-data COPY trading-data ./trading-data COPY ml-data ./ml-data COPY tli ./tli COPY backtesting ./backtesting COPY adaptive-strategy ./adaptive-strategy COPY market-data ./market-data COPY database ./database COPY common ./common COPY storage ./storage COPY backtesting ./backtesting COPY adaptive-strategy ./adaptive-strategy COPY config ./config COPY model_loader ./model_loader COPY services/trading_service ./services/trading_service COPY services/ml_training_service ./services/ml_training_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 services/backtesting_service ./services/backtesting_service COPY tests ./tests COPY tests/e2e ./tests/e2e COPY services/backtesting_service ./services/backtesting_service COPY tests ./tests COPY tests/e2e ./tests/e2e # Build backtesting service with production optimizations RUN cargo build \ --release \ --package backtesting_service \ --features standalone # ============================================================================= # CLOUD-NATIVE RUNTIME - Ubuntu Slim with Service Mesh Support # ============================================================================= FROM ubuntu:22.04-slim # Install runtime dependencies RUN apt-get update && apt-get install -y \ ca-certificates \ libssl3 \ libpq5 \ curl \ wget \ # Service mesh compatibility iptables \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Create app user and directories RUN groupadd -r foxhunt && useradd -r -g foxhunt foxhunt RUN mkdir -p /app/config /app/data /app/backtests /app/reports /app/logs \ && chown -R foxhunt:foxhunt /app # Copy binary from builder COPY --from=backtesting-builder /workspace/target/release/backtesting_service /app/backtesting_service RUN chmod +x /app/backtesting_service # Copy configuration templates COPY services/backtesting_service/config/ /app/config/ || true # Switch to app user USER foxhunt WORKDIR /app # Expose gRPC and health check ports EXPOSE 50052 8082 # Resource limits for cloud deployment ENV RUST_LOG=info ENV RUST_BACKTRACE=0 ENV FOXHUNT_CONFIG=/app/config/production.toml # Health check for Kubernetes HEALTHCHECK --interval=30s --timeout=10s --start-period=45s --retries=3 \ CMD curl -f http://localhost:8082/health || exit 1 # Graceful shutdown support STOPSIGNAL SIGTERM # Entry point with proper signal handling CMD ["./backtesting_service"]