vn6295337 Claude Opus 4.5 commited on
Commit
b06b0fc
·
1 Parent(s): 449c365

Build frontend from source in Docker instead of pre-built static

Browse files

Use multi-stage build:
- Stage 1: Node.js 20 builds frontend from source
- Stage 2: Python serves built static files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. Dockerfile +22 -5
Dockerfile CHANGED
@@ -1,6 +1,24 @@
1
  # Dockerfile for HF Spaces (Docker SDK)
2
- # Uses pre-built frontend from static/ directory
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  FROM python:3.11-slim
5
 
6
  WORKDIR /app
@@ -14,10 +32,9 @@ COPY src/ ./src/
14
  COPY a2a/ ./a2a/
15
  COPY data/ ./data/
16
  # Note: Don't copy .env file - HF Spaces injects secrets as environment variables
17
- # .env.example is for local development only
18
 
19
- # Copy pre-built frontend (built locally and committed)
20
- COPY static/ ./static/
21
 
22
  # Verify static files exist
23
  RUN ls -la /app/static/ && ls -la /app/static/assets/
@@ -29,5 +46,5 @@ EXPOSE 7860
29
  ENV PYTHONUNBUFFERED=1
30
  ENV PYTHONPATH=/app
31
 
32
- # Start server (using new consolidated path)
33
  CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # Dockerfile for HF Spaces (Docker SDK)
2
+ # Multi-stage build: Node.js for frontend, Python for backend
3
 
4
+ # Stage 1: Build frontend
5
+ FROM node:20-slim AS frontend-builder
6
+
7
+ WORKDIR /frontend
8
+
9
+ # Copy package files first for better caching
10
+ COPY frontend/package.json frontend/package-lock.json ./
11
+
12
+ # Install dependencies
13
+ RUN npm ci
14
+
15
+ # Copy frontend source code
16
+ COPY frontend/ ./
17
+
18
+ # Build the frontend
19
+ RUN npm run build
20
+
21
+ # Stage 2: Python backend with built frontend
22
  FROM python:3.11-slim
23
 
24
  WORKDIR /app
 
32
  COPY a2a/ ./a2a/
33
  COPY data/ ./data/
34
  # Note: Don't copy .env file - HF Spaces injects secrets as environment variables
 
35
 
36
+ # Copy built frontend from stage 1
37
+ COPY --from=frontend-builder /frontend/dist ./static/
38
 
39
  # Verify static files exist
40
  RUN ls -la /app/static/ && ls -la /app/static/assets/
 
46
  ENV PYTHONUNBUFFERED=1
47
  ENV PYTHONPATH=/app
48
 
49
+ # Start server
50
  CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "7860"]