MalikShehram commited on
Commit
79ee284
·
verified ·
1 Parent(s): d4f7f08

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +5 -23
Dockerfile CHANGED
@@ -1,21 +1,13 @@
1
  # ==========================================
2
  # Stage 1: Build the React + Vite Frontend
3
  # ==========================================
4
- # Upgraded to Node 20 to support Tailwind CSS v4's high-speed "Oxide" engine
5
  FROM node:20-alpine AS frontend-builder
6
-
7
  WORKDIR /app/frontend
8
 
9
- # Copy package files from the frontend folder
10
  COPY frontend/package*.json ./
11
-
12
- # Install frontend dependencies
13
  RUN npm install
14
 
15
- # Copy the rest of the frontend code
16
  COPY frontend/ .
17
-
18
- # Build the React application (this creates the optimized /dist folder)
19
  RUN npm run build
20
 
21
 
@@ -23,36 +15,26 @@ RUN npm run build
23
  # Stage 2: Setup the Python FastAPI Backend
24
  # ==========================================
25
  FROM python:3.10-slim
26
-
27
  WORKDIR /app
28
 
29
- # Copy the Python requirements file from the root directory
30
  COPY requirements.txt .
31
-
32
- # Install Python dependencies
33
  RUN pip install --no-cache-dir -r requirements.txt
34
 
35
- # Copy the backend Python code
36
- COPY backend/ /app/backend/
37
-
38
- # Copy the compiled React frontend from Stage 1 into the Python container
39
- COPY --from=frontend-builder /app/frontend/dist /app/frontend/dist
40
 
41
  # ==========================================
42
- # Stage 3: Hugging Face User Permissions
43
  # ==========================================
44
- # Hugging Face requires running as a non-root user
45
  RUN useradd -m -u 1000 user
46
  USER user
47
  ENV HOME=/home/user \
48
  PATH=/home/user/.local/bin:$PATH
49
  WORKDIR $HOME/app
50
 
51
- # Copy all remaining files into the final user home directory and set ownership
52
  COPY --chown=user . $HOME/app
53
 
54
- # Expose the default Hugging Face port
55
- EXPOSE 7860
56
 
57
- # Start the FastAPI application
58
  CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # ==========================================
2
  # Stage 1: Build the React + Vite Frontend
3
  # ==========================================
 
4
  FROM node:20-alpine AS frontend-builder
 
5
  WORKDIR /app/frontend
6
 
 
7
  COPY frontend/package*.json ./
 
 
8
  RUN npm install
9
 
 
10
  COPY frontend/ .
 
 
11
  RUN npm run build
12
 
13
 
 
15
  # Stage 2: Setup the Python FastAPI Backend
16
  # ==========================================
17
  FROM python:3.10-slim
 
18
  WORKDIR /app
19
 
 
20
  COPY requirements.txt .
 
 
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
 
 
 
 
 
23
 
24
  # ==========================================
25
+ # Stage 3: Hugging Face User Permissions & Final Assembly
26
  # ==========================================
 
27
  RUN useradd -m -u 1000 user
28
  USER user
29
  ENV HOME=/home/user \
30
  PATH=/home/user/.local/bin:$PATH
31
  WORKDIR $HOME/app
32
 
33
+ # 1. Copy the backend and local project files into the user directory
34
  COPY --chown=user . $HOME/app
35
 
36
+ # 2. Copy the compiled React frontend from Stage 1 into the EXACT folder FastAPI expects
37
+ COPY --chown=user --from=frontend-builder /app/frontend/dist $HOME/app/frontend/dist
38
 
39
+ EXPOSE 7860
40
  CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]