Spaces:
Running

michdubai commited on
Commit
0101ac9
·
verified ·
1 Parent(s): 88bb813

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -17
Dockerfile CHANGED
@@ -1,35 +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 frontend/yarn.lock* ./
7
- RUN yarn install --frozen-lockfile
 
 
 
 
8
  COPY frontend/ .
9
- RUN yarn build
10
 
11
  # ==========================================
12
- # STAGE 2: Set up Backend & Final Execution
13
  # ==========================================
14
- FROM node:20-alpine
15
  WORKDIR /app
16
 
17
- # Install 'serve' globally to handle the static frontend distribution folder
 
18
  RUN npm install -g serve
19
 
20
- # Copy compiled web assets from STAGE 1 into a final 'dist' directory
21
- COPY --from=frontend-builder /app/frontend/build ./dist
22
 
23
- # Copy the backend files into the runner context
24
  COPY backend/ ./backend
25
-
26
- # Install backend dependencies (Assuming Node.js backend. If Go/Python, we adapt)
27
  WORKDIR /app/backend
28
- COPY backend/package*.json ./
29
- RUN yarn install --frozen-lockfile
30
 
31
- # Expose the specific entry port required by Hugging Face Spaces
32
  EXPOSE 7860
33
 
34
- # Launch script: Run the backend server on background and host the frontend on port 7860
35
- CMD node server.js & 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