rajvivan commited on
Commit
fa3af66
·
verified ·
1 Parent(s): 1459888

fix: switch to single-stage build to eliminate multi-stage cache issues

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -16
Dockerfile CHANGED
@@ -1,16 +1,12 @@
1
- # Stage 1: Build the React Frontend
2
- FROM node:20-alpine AS build-step
3
-
4
- WORKDIR /app/frontend
5
- COPY frontend/package*.json ./
6
- RUN npm install --ignore-scripts
7
-
8
- COPY frontend/ ./
9
- RUN npm run build
10
-
11
- # Stage 2: Serve with Python FastAPI
12
  FROM python:3.10-slim
13
 
 
 
 
 
 
 
14
  # Set up a new user named "user" with user ID 1000 (Required by Hugging Face Spaces)
15
  RUN useradd -m -u 1000 user
16
  USER user
@@ -18,15 +14,19 @@ ENV PATH="/home/user/.local/bin:$PATH"
18
 
19
  WORKDIR /home/user/app
20
 
21
- # Copy requirement files and install Python dependencies
22
  COPY --chown=user:user requirements.txt ./
23
  RUN pip install --no-cache-dir --upgrade pip
24
  RUN pip install --no-cache-dir -r requirements.txt
25
 
26
- # Cache bust for frontend copy: v3
27
- ARG FRONTEND_COPY_BUST=3
28
- RUN mkdir -p /home/user/app/frontend/dist
29
- COPY --from=build-step --chown=user:user /app/frontend/dist/ /home/user/app/frontend/dist/
 
 
 
 
30
  COPY --chown=user:user . .
31
 
32
  EXPOSE 7860
 
1
+ # Single-stage build: Node + Python in one image (avoids multi-stage cache issues)
 
 
 
 
 
 
 
 
 
 
2
  FROM python:3.10-slim
3
 
4
+ # Install Node.js 20 as root
5
+ RUN apt-get update && apt-get install -y curl && \
6
+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
7
+ apt-get install -y nodejs && \
8
+ rm -rf /var/lib/apt/lists/*
9
+
10
  # Set up a new user named "user" with user ID 1000 (Required by Hugging Face Spaces)
11
  RUN useradd -m -u 1000 user
12
  USER user
 
14
 
15
  WORKDIR /home/user/app
16
 
17
+ # Install Python dependencies (cached separately)
18
  COPY --chown=user:user requirements.txt ./
19
  RUN pip install --no-cache-dir --upgrade pip
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ # Build React frontend (in same stage, no cross-stage cache issue)
23
+ COPY --chown=user:user frontend/package*.json ./frontend/
24
+ RUN cd frontend && npm install --ignore-scripts
25
+
26
+ COPY --chown=user:user frontend/ ./frontend/
27
+ RUN cd frontend && npm run build
28
+
29
+ # Copy remaining project files (does NOT overwrite frontend/dist/)
30
  COPY --chown=user:user . .
31
 
32
  EXPOSE 7860