munals commited on
Commit
0cba116
Β·
verified Β·
1 Parent(s): 44a4379

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +49 -0
Dockerfile ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ── Stage 1: Build React frontend ───────────────────────────────────────────
2
+ FROM node:18-slim AS frontend-build
3
+
4
+ WORKDIR /app/frontend
5
+
6
+ COPY frontend/package*.json ./
7
+ RUN npm ci
8
+
9
+ COPY frontend/ ./
10
+
11
+ # Point API calls to /api/ which Nginx will proxy to the backend
12
+ ENV VITE_API_BASE_URL=/api
13
+
14
+ RUN npm run build
15
+
16
+ # ── Stage 2: Python backend + Nginx ─────────────────────────────────────────
17
+ FROM python:3.10-slim
18
+
19
+ # Install Nginx and system dependencies
20
+ RUN apt-get update && apt-get install -y --no-install-recommends \
21
+ nginx \
22
+ && rm -rf /var/lib/apt/lists/*
23
+
24
+ WORKDIR /code
25
+
26
+ # Install Python dependencies
27
+ COPY backend/requirements.txt /code/requirements.txt
28
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
29
+
30
+ # Copy backend source
31
+ COPY backend/ /code/backend/
32
+
33
+ # Copy built frontend from Stage 1
34
+ COPY --from=frontend-build /app/frontend/dist /code/frontend/dist
35
+
36
+ # Configure Nginx: proxy /api/ to FastAPI, serve frontend for everything else
37
+ RUN echo 'server { \
38
+ listen 7860; \
39
+ location /api/ { proxy_pass http://127.0.0.1:8000/; } \
40
+ location / { root /code/frontend/dist; try_files $uri $uri/ /index.html; } \
41
+ }' > /etc/nginx/sites-enabled/default
42
+
43
+ # Startup script: run Nginx + FastAPI together
44
+ RUN printf '#!/bin/bash\nnginx &\ncd /code/backend && uvicorn main:app --host 127.0.0.1 --port 8000\n' \
45
+ > /code/start.sh && chmod +x /code/start.sh
46
+
47
+ EXPOSE 7860
48
+
49
+ CMD ["/code/start.sh"]