1+ # Multi-stage Dockerfile for BrowserPilot
2+ # Stage 1: Build the React frontend
3+ FROM node:20-alpine AS frontend-builder
4+
5+ # Set working directory for frontend
6+ WORKDIR /app/frontend
7+
8+ # Copy package files
9+ COPY frontend/package*.json ./
10+
11+ # Install all dependencies (including dev dependencies needed for build)
12+ RUN npm config set strict-ssl false && npm install
13+
14+ # Copy frontend source code
15+ COPY frontend/ ./
16+
17+ # Build the frontend
18+ RUN npm run build
19+
20+ # Stage 2: Use Playwright's official Docker image with Python (Ubuntu-based)
21+ FROM mcr.microsoft.com/playwright/python:v1.53.0-jammy
22+
23+ # Set working directory
24+ WORKDIR /app
25+
26+ # Copy Python requirements and install dependencies
27+ COPY requirements.txt .
28+ # Install compatible versions of numpy and pandas for Python 3.10
29+ RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --no-cache-dir \
30+ fastapi==0.111.0 \
31+ uvicorn[standard]==0.29.0 \
32+ playwright==1.53.0 \
33+ google-generativeai==0.5.0 \
34+ pydantic==2.7.1 \
35+ bs4==0.0.2 \
36+ lxml==5.2.1 \
37+ markdownify==0.11.6 \
38+ "numpy>=1.24.0,<2.3.0" \
39+ "pandas>=2.0.0,<2.3.0" \
40+ python-dateutil==2.9.0.post0 \
41+ pytz==2025.2 \
42+ tzdata==2025.2 \
43+ reportlab==4.4.2
44+
45+ # Copy backend source code
46+ COPY backend/ ./backend/
47+
48+ # Copy built frontend from the frontend-builder stage
49+ COPY --from=frontend-builder /app/frontend/dist ./frontend/
50+
51+ # Create outputs directory
52+ RUN mkdir -p outputs
53+
54+ # Set environment variables
55+ ENV PYTHONPATH=/app
56+ ENV PYTHONUNBUFFERED=1
57+
58+ # Expose the port the app runs on
59+ EXPOSE 8000
60+
61+ # Create a non-root user for security (the playwright image already has pwuser)
62+ RUN chown -R pwuser:pwuser /app
63+ USER pwuser
64+
65+ # Health check
66+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
67+ CMD curl -f http://localhost:8000/ || exit 1
68+
69+ # Run the application
70+ CMD ["python" , "-m" , "uvicorn" , "backend.main:app" , "--host" , "0.0.0.0" , "--port" , "8000" ]
0 commit comments