Migrated from pip to UV (v0.9.7) for faster, more reliable package management. ## Changes ### Package Management - Created `pyproject.toml` with project metadata and dependencies - Generated `uv.lock` for reproducible builds (198KB) - Migrated all dependencies from requirements.txt: - Production: 20 packages (FastAPI, SQLAlchemy, Pydantic, etc.) - Development: 6 packages (pytest, black, mypy, flake8) - Virtual environment moved from `venv/` to `.venv/` (UV default) ### Dockerfile Updates - Updated base image: python:3.11-slim → python:3.13-slim - Added UV installation via official image copy - Development stage: Uses `uv sync --frozen` for all deps - Production stage: Uses `uv sync --frozen --no-dev` for prod only - Commands now use `uv run` prefix for auto-activation - Set UV environment variables: - UV_LINK_MODE=copy (for Docker compatibility) - UV_COMPILE_BYTECODE=1 (performance) - UV_PYTHON_DOWNLOADS=never (use system Python) ### Code Fixes - Fixed Pydantic model circular import in `app/models/game_models.py` - Added runtime import of PositionRating at end of file - Called `model_rebuild()` on LineupPlayerState and GameState - Resolves "not fully defined" errors in tests ### Documentation - Updated `backend/CLAUDE.md` with UV usage: - Package management section with UV commands - Updated all code examples to use `uv run` - Daily development workflow now uses UV - Added dependency management guide (add/remove/update) - Updated virtual environment location (.venv/) ### Project Files - Added `.python-version` (3.13) for UV Python version tracking - Removed UV template files (main.py, README.md) - Kept existing .gitignore (already includes venv/ and .venv/) ## Testing - ✅ All imports work correctly - ✅ 55/55 game model tests passing - ✅ 500+ unit tests passing (same as before migration) - ✅ Test failures are pre-existing (not UV-related) ## Benefits - 10-100x faster dependency resolution - 2-3x faster installation - Better dependency conflict resolution - Single tool for everything (replaces pip, pip-tools, virtualenv) - Reproducible builds with uv.lock ## Migration Path for Team ```bash # One-time: Install UV curl -LsSf https://astral.sh/uv/install.sh | sh # In project cd backend uv sync # Creates .venv and installs everything # Daily usage uv run python -m app.main uv run pytest tests/ -v ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
70 lines
1.6 KiB
Docker
70 lines
1.6 KiB
Docker
# Backend Dockerfile for Paper Dynasty Game Engine
|
|
# Multi-stage build for optimized production image
|
|
|
|
FROM python:3.13-slim as base
|
|
|
|
# Set environment variables
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
UV_LINK_MODE=copy \
|
|
UV_COMPILE_BYTECODE=1 \
|
|
UV_PYTHON_DOWNLOADS=never
|
|
|
|
# Install system dependencies and UV
|
|
RUN apt-get update && apt-get install -y \
|
|
curl \
|
|
postgresql-client \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install UV
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
|
|
|
# Create app directory
|
|
WORKDIR /app
|
|
|
|
# Development stage
|
|
FROM base as development
|
|
|
|
# Copy dependency files
|
|
COPY pyproject.toml uv.lock ./
|
|
|
|
# Install all dependencies (including dev)
|
|
RUN uv sync --frozen
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Run with uvicorn reload for development
|
|
CMD ["uv", "run", "python", "-m", "uvicorn", "app.main:socket_app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
|
|
|
# Production stage
|
|
FROM base as production
|
|
|
|
# Copy dependency files
|
|
COPY pyproject.toml uv.lock ./
|
|
|
|
# Install production dependencies only
|
|
RUN uv sync --frozen --no-dev
|
|
|
|
# Create non-root user
|
|
RUN useradd -m -u 1000 appuser && \
|
|
chown -R appuser:appuser /app
|
|
|
|
# Copy application code
|
|
COPY --chown=appuser:appuser . .
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000/api/health || exit 1
|
|
|
|
# Run with production server
|
|
CMD ["uv", "run", "python", "-m", "uvicorn", "app.main:socket_app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"] |