trading/docker/Dockerfile.service
Viktor Barzin 5955a5a86d
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is running
fix: hardcode pip extras in Dockerfile to avoid buildx arg parsing issues
The woodpeckerci/plugin-docker-buildx was not passing the EXTRAS build
arg correctly (commas in the value were likely being parsed as list
separators), causing the image to only install dev dependencies instead
of all service extras (api, news, sentiment, trading, backtester).

Hardcode the pip install extras directly in the Dockerfile rather than
relying on the build arg.
2026-02-25 22:27:15 +00:00

49 lines
1.9 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 .
# Install all service dependencies (hardcoded to avoid build-arg comma parsing issues)
RUN pip install --no-cache-dir ".[api,news,sentiment,trading,backtester]" && 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