File size: 2,342 Bytes
c1f04cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c653b1
 
 
 
c1f04cf
 
0f2b3aa
 
 
c1f04cf
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Multi-stage Dockerfile for BrowserPilot
# Stage 1: Build the React frontend
FROM node:20-alpine AS frontend-builder

# Set working directory for frontend
WORKDIR /app/frontend

# Copy package files
COPY frontend/package*.json ./

# Install all dependencies (including dev dependencies needed for build)
RUN npm config set strict-ssl false && npm install

# Copy frontend source code
COPY frontend/ ./

# Build the frontend
RUN npm run build

# Stage 2: Use Playwright's official Docker image with Python (Ubuntu-based)
FROM mcr.microsoft.com/playwright/python:v1.53.0-jammy

# Set working directory
WORKDIR /app

# Copy Python requirements and install dependencies
COPY requirements.txt .
# Install compatible versions of numpy and pandas for Python 3.10
RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --no-cache-dir \
    fastapi==0.111.0 \
    uvicorn[standard]==0.29.0 \
    playwright==1.53.0 \
    google-generativeai==0.5.0 \
    pydantic==2.7.1 \
    bs4==0.0.2 \
    lxml==5.2.1 \
    markdownify==0.11.6 \
    "numpy>=2.0.0,<2.3.0" \
    "pandas>=2.0.0,<2.3.0" \
    python-dateutil==2.9.0.post0 \
    pytz==2025.2 \
    tzdata==2025.2 \
    reportlab==4.4.2 \
    psycopg2-binary==2.9.9 \
    asyncpg==0.29.0 \
    python-telegram-bot==21.0 \
    aiohttp==3.9.5

# Copy backend source code
COPY backend/ ./backend/

# Copy built frontend from the frontend-builder stage
COPY --from=frontend-builder /app/frontend/dist ./frontend/

# Create outputs directory
RUN mkdir -p outputs

# Copy entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Set environment variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV GRADIO_SERVER_NAME=0.0.0.0
ENV GRADIO_SERVER_PORT=8000

# Expose the port the app runs on
EXPOSE 8000

# Create a non-root user for security (the playwright image already has pwuser)
RUN chown -R pwuser:pwuser /app

# Install curl for health check before switching to non-root user
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

USER pwuser

# Health check - give app more time to start (120 seconds)
HEALTHCHECK --interval=10s --timeout=10s --start-period=120s --retries=5 \
    CMD curl -f http://localhost:8000/ || exit 1

# Run the application using entrypoint
ENTRYPOINT ["/entrypoint.sh"]