Fixed Docker build issues to complete UV migration. ## Changes ### README.md - Created backend README.md (required by hatchling build system) - Simple quick start guide referencing CLAUDE.md ### Dockerfile - Added `build-essential` for compiling native extensions (pendulum Rust code) - Updated copy steps to include README.md in both dev and prod stages - Dockerfile now successfully builds both development and production images ### .dockerignore - Added exception `!README.md` to allow README.md through - Keeps other *.md files excluded as intended ## Testing - ✅ Development image builds successfully (paper-dynasty-backend:dev-uv) - ✅ Production image builds successfully (paper-dynasty-backend:prod-uv) - ✅ Container starts and UV installs dependencies correctly - ✅ Application attempts to start (fails only on missing .env, as expected) ## Build Results - Dev image: 73 packages installed (with dev deps) - Prod image: 57 packages installed (no dev deps) - Both stages use `uv sync --frozen` for reproducible builds - Build time: ~1-2 minutes per stage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
71 lines
1.7 KiB
Docker
71 lines
1.7 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 \
|
|
build-essential \
|
|
&& 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 (including README.md referenced in pyproject.toml)
|
|
COPY pyproject.toml uv.lock README.md ./
|
|
|
|
# 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 (including README.md referenced in pyproject.toml)
|
|
COPY pyproject.toml uv.lock README.md ./
|
|
|
|
# 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"] |