trading/docker/Dockerfile.service
Viktor Barzin 5a6b20c8f1
fix: resolve 13 important issues from code review
I1: Add graceful shutdown (SIGTERM/SIGINT) to all 5 background services
I2: Fix Dockerfile healthcheck to use curl on /metrics endpoint
I3: Fix StreamConsumer.ensure_group() to only catch BUSYGROUP errors
I4: Fix SimulatedBroker to reject orders with insufficient cash/shares
I5: Move ORM attribute access inside DB session context in trades routes
I6: Add Redis-based rate limiting (10 req/min/IP) on all auth endpoints
I8: Prevent backtest background task garbage collection
I9: Use Numeric(16,6) instead of Float for financial columns in migration
I10: Add index on trades.created_at for time-range queries
I11: Bind infrastructure ports to 127.0.0.1 in docker-compose
I12: Add migrations init service; all app services depend on it
I13: Fix user enumeration in login_begin (return options for non-existent users)
2026-02-22 17:58:01 +00:00

49 lines
1.8 KiB
Desktop File

# Multi-stage Dockerfile for all Python microservices.
# Build args:
# EXTRAS — pip optional-dependency groups (e.g. "news", "sentiment,trading")
# SERVICE_MODULE — Python module name under services/ (e.g. "news_fetcher")
# ---------------------------------------------------------------------------
# Stage 1: builder — install Python dependencies
# ---------------------------------------------------------------------------
FROM python:3.12-slim AS builder
WORKDIR /app
# Copy project metadata and source so pip can resolve the local package
COPY pyproject.toml .
COPY shared/ shared/
COPY services/ services/
COPY backtester/ backtester/
COPY alembic/ alembic/
COPY alembic.ini .
ARG EXTRAS="dev"
RUN pip install --no-cache-dir ".[$EXTRAS]" && pip install --no-cache-dir curl_cffi 2>/dev/null || true
# ---------------------------------------------------------------------------
# Stage 2: slim runtime image
# ---------------------------------------------------------------------------
FROM python:3.12-slim
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy installed packages and CLI entry-points from the builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application source code
COPY --from=builder /app .
ARG SERVICE_MODULE="api_gateway"
ENV SERVICE_MODULE=${SERVICE_MODULE}
ARG HEALTH_PORT="9090"
ENV HEALTH_PORT=${HEALTH_PORT}
# Check /metrics endpoint (all services expose it via OpenTelemetry)
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -sf http://localhost:${HEALTH_PORT}/metrics > /dev/null || exit 1
CMD python -m services.${SERVICE_MODULE}.main