Dockerfile 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Stage 1: Build React Frontend
  2. FROM node:20-alpine AS frontend-builder
  3. # Set working directory for frontend
  4. WORKDIR /app/frontend
  5. # Copy frontend package files and install dependencies
  6. COPY frontend/package.json ./
  7. COPY frontend/package-lock.json ./
  8. # If you use yarn or pnpm, adjust accordingly (e.g., copy yarn.lock or pnpm-lock.yaml and use yarn install or pnpm install)
  9. RUN npm install
  10. # Copy the rest of the frontend source code
  11. COPY frontend/ ./
  12. # Build the frontend
  13. RUN npm run build
  14. # Stage 2: Python Backend
  15. FROM docker.io/langchain/langgraph-api:3.11
  16. # -- Install UV --
  17. # First install curl, then install UV using the standalone installer
  18. RUN apt-get update && apt-get install -y curl && \
  19. curl -LsSf https://astral.sh/uv/install.sh | sh && \
  20. apt-get clean && rm -rf /var/lib/apt/lists/*
  21. ENV PATH="/root/.local/bin:$PATH"
  22. # -- End of UV installation --
  23. # -- Copy built frontend from builder stage --
  24. # The app.py expects the frontend build to be at ../frontend/dist relative to its own location.
  25. # If app.py is at /deps/backend/src/agent/app.py, then ../frontend/dist resolves to /deps/frontend/dist.
  26. COPY --from=frontend-builder /app/frontend/dist /deps/frontend/dist
  27. # -- End of copying built frontend --
  28. # -- Adding local package . --
  29. ADD backend/ /deps/backend
  30. # -- End of local package . --
  31. # -- Installing all local dependencies using UV --
  32. # First, we need to ensure pip is available for UV to use
  33. RUN uv pip install --system pip setuptools wheel
  34. # Install dependencies with UV, respecting constraints
  35. RUN cd /deps/backend && \
  36. PYTHONDONTWRITEBYTECODE=1 UV_SYSTEM_PYTHON=1 uv pip install --system -c /api/constraints.txt -e .
  37. # -- End of local dependencies install --
  38. ENV LANGGRAPH_HTTP='{"app": "/deps/backend/src/agent/app.py:app"}'
  39. ENV LANGSERVE_GRAPHS='{"agent": "/deps/backend/src/agent/graph.py:graph"}'
  40. # -- Ensure user deps didn't inadvertently overwrite langgraph-api
  41. # Create all required directories that the langgraph-api package expects
  42. RUN mkdir -p /api/langgraph_api /api/langgraph_runtime /api/langgraph_license /api/langgraph_storage && \
  43. touch /api/langgraph_api/__init__.py /api/langgraph_runtime/__init__.py /api/langgraph_license/__init__.py /api/langgraph_storage/__init__.py
  44. # Use pip for this specific package as it has poetry-based build requirements
  45. RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir --no-deps -e /api
  46. # -- End of ensuring user deps didn't inadvertently overwrite langgraph-api --
  47. # -- Removing pip from the final image (but keeping UV) --
  48. RUN uv pip uninstall --system pip setuptools wheel && \
  49. rm -rf /usr/local/lib/python*/site-packages/pip* /usr/local/lib/python*/site-packages/setuptools* /usr/local/lib/python*/site-packages/wheel* && \
  50. find /usr/local/bin -name "pip*" -delete
  51. # -- End of pip removal --
  52. WORKDIR /deps/backend