Spaces:
Running

michdubai commited on
Commit
89a0114
·
verified ·
1 Parent(s): a1478d0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -11
Dockerfile CHANGED
@@ -1,34 +1,38 @@
1
  # ==========================================
2
- # STAGE 1: Build the React Frontend Assets
3
  # ==========================================
4
  FROM node:20-alpine AS frontend-builder
5
  WORKDIR /app/frontend
 
 
6
  COPY frontend/package*.json ./
7
  RUN npm install
 
 
8
  COPY frontend/ .
9
  RUN npm run build
10
 
11
  # ==========================================
12
- # STAGE 2: Setup Python Backend & Runner
13
  # ==========================================
14
  FROM python:3.11-slim
15
  WORKDIR /app
16
 
17
- # Install Node and NPM inside the Python image to handle the static frontend serving
18
- RUN apt-get update && apt-get install -y nodejs npm && rm -rf /lib/apt/lists/*
19
  RUN npm install -g serve
20
 
21
- # Copy the compiled React assets from STAGE 1
22
- COPY --from=frontend-builder /app/frontend/build ./dist
23
 
24
- # Copy backend files and setup dependencies
25
  COPY backend/ ./backend
26
  WORKDIR /app/backend
27
  RUN pip install --no-cache-dir -r requirements.txt
28
 
29
- # Hugging Face Spaces mandates container exposure on port 7860
30
  EXPOSE 7860
31
 
32
- # Launch Step: Start the Python FastAPI server on port 8000 in background,
33
- # and serve the static frontend app directly on Hugging Face's port 7860
34
- CMD uvicorn main:app --host 0.0.0.0 --port 8000 & serve -s /app/dist -l 7860
 
1
  # ==========================================
2
+ # STAGE 1: Build the Vite Frontend Assets
3
  # ==========================================
4
  FROM node:20-alpine AS frontend-builder
5
  WORKDIR /app/frontend
6
+
7
+ # Copy dependencies descriptor files
8
  COPY frontend/package*.json ./
9
  RUN npm install
10
+
11
+ # Copy frontend source and build it
12
  COPY frontend/ .
13
  RUN npm run build
14
 
15
  # ==========================================
16
+ # STAGE 2: Setup Python Backend & Final Image
17
  # ==========================================
18
  FROM python:3.11-slim
19
  WORKDIR /app
20
 
21
+ # Install Node.js runtime inside the Python container to serve frontend static pages
22
+ RUN apt-get update && apt-get install -y nodejs npm && rm -rf /var/lib/apt/lists/*
23
  RUN npm install -g serve
24
 
25
+ # Copy Vite production build assets from Stage 1 into /app/dist
26
+ COPY --from=frontend-builder /app/frontend/dist ./dist
27
 
28
+ # Set up the Python Backend requirements
29
  COPY backend/ ./backend
30
  WORKDIR /app/backend
31
  RUN pip install --no-cache-dir -r requirements.txt
32
 
33
+ # Hugging Face Spaces strictly requires listening on port 7860
34
  EXPOSE 7860
35
 
36
+ # Launch Step: Start the Python backend (app.py) on port 8000,
37
+ # and start the frontend serving application directly on port 7860
38
+ CMD uvicorn app:app --host 0.0.0.0 --port 8000 & serve -s /app/dist -l 7860