adeem6 commited on
Commit
d76a550
Β·
verified Β·
1 Parent(s): 8b3521b

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +94 -0
Dockerfile ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ── Stage 1: Build React frontend ─────────────────────────────────────
2
+ FROM node:18-slim AS frontend-build
3
+
4
+ WORKDIR /app/frontend
5
+
6
+ # Install dependencies
7
+ COPY frontend/package*.json ./
8
+ RUN npm ci
9
+
10
+ # Copy source and build
11
+ COPY frontend/ ./
12
+ # Point API to same host (served via nginx proxy)
13
+ ENV VITE_API_BASE_URL=/api
14
+ RUN npm run build
15
+
16
+ # ── Stage 2: Final image ───────────────────────────────────────────────
17
+ FROM python:3.10-slim
18
+
19
+ # System deps for OpenCV + YOLO
20
+ RUN apt-get update && apt-get install -y --no-install-recommends \
21
+ libgl1 \
22
+ libglib2.0-0 \
23
+ libsm6 \
24
+ libxext6 \
25
+ libxrender-dev \
26
+ nginx \
27
+ && rm -rf /var/lib/apt/lists/*
28
+
29
+ WORKDIR /app
30
+
31
+ # ── Python deps ────────────────────────────────────────────────────────
32
+ COPY backend/requirements.txt ./
33
+ RUN pip install --no-cache-dir -r requirements.txt
34
+
35
+ # ── Backend source ─────────────────────────────────────────────────────
36
+ COPY backend/ ./backend/
37
+
38
+ # ── Frontend build output ──────────────────────────────────────────────
39
+ COPY --from=frontend-build /app/frontend/dist /app/frontend/dist
40
+
41
+ # Copy Hajj videos so the pipeline can find them
42
+ COPY frontend/public/hajj_real_video.mp4 ./backend/hajj_real_video.mp4
43
+ COPY frontend/public/hajj_video_h264.mp4 ./backend/hajj_video_h264.mp4
44
+
45
+ # ── Nginx config: serve frontend + proxy /api β†’ FastAPI ───────────────
46
+ RUN cat > /etc/nginx/sites-available/default << 'EOF'
47
+ server {
48
+ listen 7860;
49
+ server_name _;
50
+
51
+ # Serve React build
52
+ root /app/frontend/dist;
53
+ index index.html;
54
+
55
+ # Proxy API calls to FastAPI
56
+ location /api/ {
57
+ proxy_pass http://127.0.0.1:8000/api/;
58
+ proxy_http_version 1.1;
59
+ proxy_set_header Host $host;
60
+ proxy_set_header X-Real-IP $remote_addr;
61
+ proxy_read_timeout 120s;
62
+ }
63
+
64
+ location /health {
65
+ proxy_pass http://127.0.0.1:8000/health;
66
+ }
67
+
68
+ # SPA fallback β€” all unknown routes β†’ index.html
69
+ location / {
70
+ try_files $uri $uri/ /index.html;
71
+ }
72
+ }
73
+ EOF
74
+
75
+ # ── Startup script ─────────────────────────────────────────────────────
76
+ RUN cat > /app/start.sh << 'EOF'
77
+ #!/bin/bash
78
+ set -e
79
+
80
+ echo "Starting FastAPI backend..."
81
+ cd /app/backend
82
+ uvicorn api:app --host 127.0.0.1 --port 8000 &
83
+
84
+ echo "Starting Nginx..."
85
+ nginx -g "daemon off;" &
86
+
87
+ wait -n
88
+ EOF
89
+ RUN chmod +x /app/start.sh
90
+
91
+ # HuggingFace Spaces requires port 7860
92
+ EXPOSE 7860
93
+
94
+ CMD ["/app/start.sh"]