Files
vincent 2d95ae50a5 feat: Sidecar V2 — multi-pool provider proxy with 429 cooldown
- proxy.py: Fix route path duplication (v1/v1 → v1) when upstream
  base URL already includes /v1 prefix
- proxy.py: Fix _emergency_count global variable for metrics tracking
- server.py: Add logging.basicConfig(level=logging.INFO) for structlog
  INFO-level log visibility
- Full multi-pool routing: primary → fallback → emergency passthrough
- Per-backend rate limiting with RPM-based token bucket
- 429 cooldown mechanism with automatic recovery
- Dashboard with SSE real-time monitoring
- Admin API for backend/pool/config management
- SQLite-backed persistence with encrypted API key storage
- Docker compose deployment

Deployed by opengineer 严维序 as BIZ-50 Step 4
2026-06-25 21:20:32 +08:00

46 lines
1.2 KiB
Docker

# Sidecar V2 — Multi-Pool Provider Proxy
FROM python:3.12-slim AS builder
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY config.py crypto.py main.py server.py proxy.py router.py \
pool_manager.py cooldown_manager.py rate_limiter.py __init__.py \
dashboard.html ./
COPY storage/ ./storage/
# Create data directory
RUN mkdir -p /app/data /app/data/backups
FROM python:3.12-slim
WORKDIR /app
# Copy built artifacts
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /app /app
# Environment
ENV SIDECAR_HOST=0.0.0.0
ENV SIDECAR_PORT=9190
ENV SIDECAR_METRICS_PORT=9191
ENV SIDECAR_DB_PATH=/app/data/sidecar_v2.db
ENV SIDECAR_BACKUP_DIR=/app/data/backups
ENV SIDECAR_ENCRYPTION_KEY=
ENV SIDECAR_ADMIN_TOKEN=
ENV LOG_FORMAT=json
ENV PYTHONUNBUFFERED=1
EXPOSE 9190 9191
VOLUME ["/app/data"]
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:9190/health')" || exit 1
ENTRYPOINT ["python3", "main.py"]