HyperCluster/Fara-BrowserUse
5
1# Stage 1: Build React frontend
2FROM node:20-slim AS frontend-builder
3
4WORKDIR /app/frontend
5
6# Copy package files
7COPY package*.json ./
8
9# Install dependencies
10RUN npm ci
11
12# Copy source files
13COPY . .
14
15# Build the React app
16RUN npm run build
17
18# Stage 2: Python backend + serve frontend
19FROM python:3.12-slim-trixie
20
21# Copy uv from the official distroless image (recommended approach)
22COPY --from=ghcr.io/astral-sh/uv:0.9.15 /uv /uvx /bin/
23
24# Install system dependencies for Playwright and nginx
25RUN apt-get update && apt-get install -y \
26 nginx \
27 supervisor \
28 libnss3 \
29 libnspr4 \
30 libatk1.0-0 \
31 libatk-bridge2.0-0 \
32 libcups2 \
33 libdrm2 \
34 libxkbcommon0 \
35 libxcomposite1 \
36 libxdamage1 \
37 libxfixes3 \
38 libxrandr2 \
39 libgbm1 \
40 libasound2 \
41 libpango-1.0-0 \
42 libpangocairo-1.0-0 \
43 libcairo2 \
44 libatspi2.0-0 \
45 xvfb \
46 fonts-liberation \
47 libappindicator3-1 \
48 libu2f-udev \
49 libvulkan1 \
50 wget \
51 && rm -rf /var/lib/apt/lists/*
52
53# Create a new user named "user" with user ID 1000 (required for HF Spaces)
54RUN useradd -m -u 1000 user
55
56# Create necessary directories with proper permissions for nginx (before switching user)
57RUN mkdir -p /var/log/nginx /var/lib/nginx /var/cache/nginx /run \
58 && chown -R user:user /var/log/nginx /var/lib/nginx /var/cache/nginx /run \
59 && chmod -R 755 /var/log/nginx /var/lib/nginx /var/cache/nginx /run
60
61# Configure nginx (needs root for /etc/nginx)
62COPY nginx.conf /etc/nginx/nginx.conf
63
64# Configure supervisor
65COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
66
67# Allow user to run supervisor
68RUN chown -R user:user /etc/supervisor
69
70# Switch to the "user" user
71USER user
72
73# Set home to the user's home directory
74ENV HOME=/home/user \
75 PATH=/home/user/.local/bin:$PATH
76
77# Set the working directory to the user's home directory
78WORKDIR $HOME/app
79
80# Copy backend code and sync with locked dependencies
81COPY --chown=user:user backend/ ./backend/
82RUN cd backend && uv sync
83
84# Copy FARA source
85COPY --chown=user:user fara/ ./fara/
86
87# Activate the virtual environment by adding it to PATH
88ENV PATH="$HOME/app/backend/.venv/bin:$PATH"
89
90# Install Playwright browsers
91RUN playwright install chromium
92
93# Copy built frontend from Stage 1
94COPY --chown=user:user --from=frontend-builder /app/frontend/dist ./static
95
96# Expose port
97EXPOSE 7860
98
99# Set environment variables
100ENV PYTHONUNBUFFERED=1
101
102# Start supervisor (manages nginx + python backend)
103CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
104 