# 🏗️ Multi-stage build for optimal caching and size FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder # 🔧 System dependencies layer (cached unless OS changes) RUN apt-get update && apt-get install -y \ postgresql-client \ git \ curl \ build-essential \ gnupg \ ca-certificates \ && rm -rf /var/lib/apt/lists/* # 📦 Install Node.js LTS (cached until Node.js version changes) RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* \ && npm upgrade -g npm WORKDIR /app # 📦 Node.js dependencies layer (cached unless package*.json changes) COPY package.json package-lock.json ./ RUN npm ci # 🐍 Python dependencies compilation (with Rust/maturin support) COPY pyproject.toml uv.lock ./ RUN uv sync --frozen --no-install-project # 🏗️ Frontend build (build with all dependencies) COPY . . # Install local package in builder stage RUN uv sync --frozen --no-editable RUN npm run build # 🚀 Production stage FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim # 🔧 Runtime dependencies only RUN apt-get update && apt-get install -y \ postgresql-client \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # 🧠 ML models cache setup (cached unless HF environment changes) RUN mkdir -p /app/.cache/huggingface && chmod 755 /app/.cache/huggingface ENV TRANSFORMERS_CACHE=/app/.cache/huggingface ENV HF_HOME=/app/.cache/huggingface # Принудительно используем CPU-only версию PyTorch ENV TORCH_CUDA_AVAILABLE=0 # 🚀 Application code (rebuilt on any code change) COPY . . # 📦 Copy compiled Python environment from builder (includes all dependencies + local package) COPY --from=builder /app/.venv /app/.venv ENV PATH="/app/.venv/bin:$PATH" # 📦 Copy built frontend from builder stage COPY --from=builder /app/dist ./dist EXPOSE 8000 CMD ["python", "-m", "granian", "main:app", "--interface", "asgi", "--host", "0.0.0.0", "--port", "8000"]