Upload Dockerfile.txt
Browse files- Dockerfile.txt +103 -0
Dockerfile.txt
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Stage 1: Build React frontend
|
| 2 |
+
FROM node:20-slim AS frontend-builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /app/frontend
|
| 5 |
+
|
| 6 |
+
# Copy package files
|
| 7 |
+
COPY package*.json ./
|
| 8 |
+
|
| 9 |
+
# Install dependencies
|
| 10 |
+
RUN npm ci
|
| 11 |
+
|
| 12 |
+
# Copy source files
|
| 13 |
+
COPY . .
|
| 14 |
+
|
| 15 |
+
# Build the React app
|
| 16 |
+
RUN npm run build
|
| 17 |
+
|
| 18 |
+
# Stage 2: Python backend + serve frontend
|
| 19 |
+
FROM python:3.12-slim-trixie
|
| 20 |
+
|
| 21 |
+
# Copy uv from the official distroless image (recommended approach)
|
| 22 |
+
COPY --from=ghcr.io/astral-sh/uv:0.9.15 /uv /uvx /bin/
|
| 23 |
+
|
| 24 |
+
# Install system dependencies for Playwright and nginx
|
| 25 |
+
RUN 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)
|
| 54 |
+
RUN useradd -m -u 1000 user
|
| 55 |
+
|
| 56 |
+
# Create necessary directories with proper permissions for nginx (before switching user)
|
| 57 |
+
RUN 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)
|
| 62 |
+
COPY nginx.conf /etc/nginx/nginx.conf
|
| 63 |
+
|
| 64 |
+
# Configure supervisor
|
| 65 |
+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
| 66 |
+
|
| 67 |
+
# Allow user to run supervisor
|
| 68 |
+
RUN chown -R user:user /etc/supervisor
|
| 69 |
+
|
| 70 |
+
# Switch to the "user" user
|
| 71 |
+
USER user
|
| 72 |
+
|
| 73 |
+
# Set home to the user's home directory
|
| 74 |
+
ENV HOME=/home/user \
|
| 75 |
+
PATH=/home/user/.local/bin:$PATH
|
| 76 |
+
|
| 77 |
+
# Set the working directory to the user's home directory
|
| 78 |
+
WORKDIR $HOME/app
|
| 79 |
+
|
| 80 |
+
# Copy backend code and sync with locked dependencies
|
| 81 |
+
COPY --chown=user:user backend/ ./backend/
|
| 82 |
+
RUN cd backend && uv sync
|
| 83 |
+
|
| 84 |
+
# Copy FARA source
|
| 85 |
+
COPY --chown=user:user fara/ ./fara/
|
| 86 |
+
|
| 87 |
+
# Activate the virtual environment by adding it to PATH
|
| 88 |
+
ENV PATH="$HOME/app/backend/.venv/bin:$PATH"
|
| 89 |
+
|
| 90 |
+
# Install Playwright browsers
|
| 91 |
+
RUN playwright install chromium
|
| 92 |
+
|
| 93 |
+
# Copy built frontend from Stage 1
|
| 94 |
+
COPY --chown=user:user --from=frontend-builder /app/frontend/dist ./static
|
| 95 |
+
|
| 96 |
+
# Expose port
|
| 97 |
+
EXPOSE 7860
|
| 98 |
+
|
| 99 |
+
# Set environment variables
|
| 100 |
+
ENV PYTHONUNBUFFERED=1
|
| 101 |
+
|
| 102 |
+
# Start supervisor (manages nginx + python backend)
|
| 103 |
+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|