Dockerfile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. iproute2 \
  20. libcap2-bin \
  21. openssh-client \
  22. && rm -rf /var/lib/apt/lists/*
  23. # Allow binding to privileged ports (e.g. 990/FTPS) as non-root user.
  24. # File capabilities are more reliable than Docker cap_add with user: directive,
  25. # which depends on ambient capability support in the container runtime.
  26. RUN setcap cap_net_bind_service=+ep "$(readlink -f /usr/local/bin/python3)"
  27. # Install Python dependencies with cache mount
  28. COPY requirements.txt ./
  29. RUN --mount=type=cache,target=/root/.cache/pip \
  30. pip install --root-user-action=ignore -r requirements.txt
  31. # Copy backend
  32. COPY backend/ ./backend/
  33. # Copy built frontend from builder stage
  34. COPY --from=frontend-builder /app/static ./static
  35. # Create data directory for persistent storage
  36. # chmod 777 allows running as non-root user (e.g., with docker compose user: directive)
  37. RUN mkdir -p /app/data /app/logs && chmod 777 /app/data /app/logs
  38. # Environment variables
  39. ENV PYTHONUNBUFFERED=1
  40. ENV DATA_DIR=/app/data
  41. ENV LOG_DIR=/app/logs
  42. ENV PORT=8000
  43. EXPOSE 322
  44. EXPOSE 990
  45. EXPOSE 3000
  46. EXPOSE 3002
  47. EXPOSE 6000
  48. EXPOSE 8000
  49. EXPOSE 8883
  50. EXPOSE 50000-50100
  51. # Health check (uses PORT env var via shell)
  52. HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
  53. CMD python -c "import urllib.request, os; urllib.request.urlopen(f'http://localhost:{os.environ.get(\"PORT\", \"8000\")}/health')" || exit 1
  54. # Run the application
  55. # Use standard asyncio loop (uvloop has permission issues in some Docker environments)
  56. # Port is configurable via PORT environment variable (default: 8000)
  57. CMD ["sh", "-c", "uvicorn backend.app.main:app --host 0.0.0.0 --port ${PORT:-8000} --loop asyncio"]