dawit45 commited on
Commit
224a9bf
·
verified ·
1 Parent(s): 9a44293

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -28
Dockerfile CHANGED
@@ -1,44 +1,37 @@
1
- # Stage 1: Build the React Application
2
- FROM docker.io/library/node:20-slim AS build-stage
3
-
4
  WORKDIR /app
5
-
6
- # Install dependencies first for Docker caching efficiency
7
  COPY package*.json ./
8
  RUN npm install
9
-
10
- # Copy source code and build
11
  COPY . .
12
  RUN npm run build
13
 
14
- # Stage 2: Serve with Python/Gunicorn
15
- FROM docker.io/library/python:3.9-slim
16
-
17
- WORKDIR /code
18
-
19
- # Copy the compiled React assets from Stage 1
20
- COPY --from=build-stage /app/dist /code/dist
21
 
22
- # Copy backend server files
23
- COPY requirements.txt .
24
- COPY app.py .
25
 
26
- # Install Python production server dependencies
27
- RUN pip install --no-cache-dir -r requirements.txt
28
-
29
- # Create a non-root user for security compliance on Hugging Face
30
  RUN useradd -m -u 1000 user
31
- USER user
32
  ENV HOME=/home/user \
33
  PATH=/home/user/.local/bin:$PATH
34
 
35
- WORKDIR $HOME/app
36
- COPY --from=build-stage --chown=user /app/dist $HOME/app/dist
37
- COPY --chown=user requirements.txt $HOME/app/
38
- COPY --chown=user app.py $HOME/app/
 
 
 
 
 
 
 
39
 
40
- # Expose the standard Hugging Face port
41
  EXPOSE 7860
42
 
43
- # Execute Gunicorn with 4 workers to handle concurrent health probes and user traffic
 
44
  CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
 
1
+ # --- STAGE 1: Build React ---
2
+ FROM node:20-slim AS build-stage
 
3
  WORKDIR /app
 
 
4
  COPY package*.json ./
5
  RUN npm install
 
 
6
  COPY . .
7
  RUN npm run build
8
 
9
+ # --- STAGE 2: Serve with Python ---
10
+ FROM python:3.9-slim
11
+ WORKDIR /app
 
 
 
 
12
 
13
+ # 1. Install system dependencies in Build Phase
14
+ RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
 
15
 
16
+ # 2. Setup User
 
 
 
17
  RUN useradd -m -u 1000 user
 
18
  ENV HOME=/home/user \
19
  PATH=/home/user/.local/bin:$PATH
20
 
21
+ # 3. Install Python requirements
22
+ COPY --chown=user requirements.txt .
23
+ RUN pip install --no-cache-dir -r requirements.txt
24
+
25
+ # 4. Copy Application Files
26
+ # We copy everything into /app and ensure the 'user' owns it
27
+ COPY --from=build-stage --chown=user /app/dist ./dist
28
+ COPY --chown=user app.py .
29
+
30
+ # 5. Set permissions
31
+ USER user
32
 
 
33
  EXPOSE 7860
34
 
35
+ # 6. Launch Gunicorn
36
+ # Note: app:app refers to app.py and the 'app' variable inside it
37
  CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]