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)
This commit is contained in:
Viktor Barzin 2026-02-22 17:58:01 +00:00
parent 2a56727267
commit 5a6b20c8f1
No known key found for this signature in database
GPG key ID: 0EB088298288D958
13 changed files with 355 additions and 188 deletions

View file

@ -19,13 +19,15 @@ COPY alembic/ alembic/
COPY alembic.ini .
ARG EXTRAS="dev"
RUN pip install --no-cache-dir ".[$EXTRAS]"
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
@ -37,9 +39,11 @@ COPY --from=builder /app .
ARG SERVICE_MODULE="api_gateway"
ENV SERVICE_MODULE=${SERVICE_MODULE}
ARG HEALTH_PORT="9090"
ENV HEALTH_PORT=${HEALTH_PORT}
# Simple health check — verify the Python process is running
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD python -c "import sys; sys.exit(0)" || exit 1
# 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