Dockerfile 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Build frontend
  2. FROM node:22-bookworm-slim AS frontend-builder
  3. WORKDIR /app/frontend
  4. # Copy package files first for better caching
  5. COPY frontend/package*.json ./
  6. # Use cache mount for npm
  7. RUN --mount=type=cache,target=/root/.npm \
  8. npm ci
  9. COPY frontend/ ./
  10. RUN npm run build
  11. # Production image
  12. FROM python:3.13-slim
  13. WORKDIR /app
  14. # Install system dependencies
  15. ENV DEBIAN_FRONTEND=noninteractive
  16. RUN apt-get update && apt-get install -y --no-install-recommends \
  17. curl \
  18. ffmpeg \
  19. && rm -rf /var/lib/apt/lists/*
  20. # Install Python dependencies with cache mount
  21. COPY requirements.txt ./
  22. RUN --mount=type=cache,target=/root/.cache/pip \
  23. pip install --root-user-action=ignore -r requirements.txt
  24. # Copy backend
  25. COPY backend/ ./backend/
  26. # Copy built frontend from builder stage
  27. COPY --from=frontend-builder /app/static ./static
  28. # Create data directory for persistent storage
  29. RUN mkdir -p /app/data /app/logs
  30. # Environment variables
  31. ENV PYTHONUNBUFFERED=1
  32. ENV DATA_DIR=/app/data
  33. ENV LOG_DIR=/app/logs
  34. ENV PORT=8000
  35. EXPOSE 8000
  36. # Health check (uses PORT env var via shell)
  37. HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
  38. CMD python -c "import urllib.request, os; urllib.request.urlopen(f'http://localhost:{os.environ.get(\"PORT\", \"8000\")}/health')" || exit 1
  39. # Run the application
  40. # Use standard asyncio loop (uvloop has permission issues in some Docker environments)
  41. # Port is configurable via PORT environment variable (default: 8000)
  42. CMD sh -c "uvicorn backend.app.main:app --host 0.0.0.0 --port ${PORT:-8000} --loop asyncio"