KaTaKat commited on
Commit
f2b5f83
·
1 Parent(s): 02efb7d

Fix Dockerfile for Hugging Face build

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -51
Dockerfile CHANGED
@@ -1,70 +1,43 @@
1
- # --- Stage 1: Build Frontend ---
2
  FROM node:20-slim AS build-frontend
3
  WORKDIR /app/frontend
4
- <<<<<<< HEAD
5
- # Optimize by copying only package files first
6
- =======
7
- >>>>>>> origin/main
8
  COPY frontend/package*.json ./
9
- RUN npm install
 
 
 
 
10
  COPY frontend/ ./
 
 
11
  RUN npm run build
12
 
13
- # --- Stage 2: Final Image ---
 
14
  FROM python:3.11-slim
15
- <<<<<<< HEAD
16
- # Hugging Face Spaces runtime requirement: user 1000
17
  RUN useradd -m -u 1000 user
18
  USER user
19
- ENV PATH="/home/user/.local/bin:$PATH"
20
- WORKDIR /app
21
 
22
- # Install system dependencies
23
- USER root
24
- =======
25
  WORKDIR /app
26
 
27
- # Install system dependencies for PDF and ML
28
- >>>>>>> origin/main
29
- RUN apt-get update && apt-get install -y \
30
- build-essential \
31
- libpq-dev \
32
- && rm -rf /var/lib/apt/lists/*
33
- <<<<<<< HEAD
34
- USER user
35
-
36
- # Install Python requirements
37
- COPY --chown=user:user backend/requirements.txt ./
38
- RUN pip install --no-cache-dir --upgrade pip && \
39
- pip install --no-cache-dir -r requirements.txt && \
40
- pip install --no-cache-dir gunicorn
41
-
42
- # Copy backend code
43
- COPY --chown=user:user backend/ ./
44
 
45
- # Copy built frontend to backend's build folder
46
- COPY --chown=user:user --from=build-frontend /app/frontend/dist ./build
47
- =======
48
 
49
- # Copy backend requirements and install
50
- COPY backend/requirements.txt ./
51
- RUN pip install --no-cache-dir -r requirements.txt
52
- RUN pip install gunicorn
53
 
54
- # Copy backend code
55
- COPY backend/ ./
56
-
57
- # Copy built frontend from Stage 1 to backend's build folder
58
- # Note: server.py expects the React app in a 'build' folder
59
- COPY --from=build-frontend /app/frontend/dist ./build
60
- >>>>>>> origin/main
61
-
62
- # Set Environment Variables
63
  ENV PORT=7860
64
- ENV PYTHONUNBUFFERED=1
65
-
66
- # Expose the port HF Spaces expects
67
  EXPOSE 7860
68
 
69
- # Run the server using gunicorn
70
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "--workers", "1", "server:server"]
 
1
+ # ---------- Stage 1: Build Frontend ----------
2
  FROM node:20-slim AS build-frontend
3
  WORKDIR /app/frontend
4
+
5
+ # Copy only package files first (better caching)
 
 
6
  COPY frontend/package*.json ./
7
+
8
+ # Use npm ci for reproducible HF builds
9
+ RUN npm ci
10
+
11
+ # Copy frontend source
12
  COPY frontend/ ./
13
+
14
+ # Build frontend (Vite → dist)
15
  RUN npm run build
16
 
17
+
18
+ # ---------- Stage 2: Final Image ----------
19
  FROM python:3.11-slim
20
+
21
+ # Create HF-compatible user (required)
22
  RUN useradd -m -u 1000 user
23
  USER user
 
 
24
 
25
+ ENV PATH="/home/user/.local/bin:$PATH"
 
 
26
  WORKDIR /app
27
 
28
+ # Install backend dependencies + gunicorn
29
+ COPY --chown=user backend/requirements.txt ./requirements.txt
30
+ RUN pip install --no-cache-dir -r requirements.txt gunicorn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ # Copy backend source
33
+ COPY --chown=user backend/ ./
 
34
 
35
+ # Copy frontend build output
36
+ COPY --from=build-frontend --chown=user /app/frontend/dist ./build
 
 
37
 
38
+ # Hugging Face required port
 
 
 
 
 
 
 
 
39
  ENV PORT=7860
 
 
 
40
  EXPOSE 7860
41
 
42
+ # Start backend
43
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "--workers", "1", "server:server"]