perf: switch to uv for faster dependency installation
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

- Replace pip with uv in Dockerfile.service builder stage (~5-10x faster)
- Replace pip with uv in CI test step
- Separate pyproject.toml copy from source copy in Dockerfile for better
  Docker layer caching (deps only reinstalled when pyproject.toml changes)
- Add cache_from for buildx to reuse layers from previous builds
- Remove pip cache workaround from test step (not persisted in K8s)
This commit is contained in:
Viktor Barzin 2026-02-25 22:55:58 +00:00
parent 5955a5a86d
commit 0a017f52cb
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 23 additions and 20 deletions

View file

@ -1,6 +1,5 @@
# 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")
# ---------------------------------------------------------------------------
@ -10,16 +9,28 @@ FROM python:3.12-slim AS builder
WORKDIR /app
# Copy project metadata and source so pip can resolve the local package
# Install uv for fast dependency resolution
RUN pip install uv
# Copy ONLY dependency metadata first — this layer is cached until
# pyproject.toml changes, so dependency install is skipped on pure code changes.
COPY pyproject.toml .
# Create minimal package stubs so uv can resolve the local editable install
# without copying all source (which would bust the cache on every commit).
RUN mkdir -p shared services backtester && \
uv pip install --system --no-cache-dir ".[api,news,sentiment,trading,backtester]" && \
uv pip install --system --no-cache-dir curl_cffi 2>/dev/null || true
# NOW copy the actual source code (changes here don't re-trigger dep install)
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
# Re-install in-place so the package metadata points to actual source
RUN uv pip install --system --no-cache-dir --no-deps -e .
# ---------------------------------------------------------------------------
# Stage 2: slim runtime image