Álvaro Valenzuela Valdes commited on
Commit
f59c380
·
1 Parent(s): 439261e

deploy: Add unified Docker deployment files for Hugging Face Spaces

Browse files
Files changed (3) hide show
  1. Dockerfile +47 -0
  2. nginx.conf +26 -0
  3. start.sh +10 -0
Dockerfile ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Build Frontend
2
+ FROM node:20-slim AS frontend-builder
3
+ WORKDIR /app/frontend
4
+ COPY frontend/package.json frontend/package-lock.json* ./
5
+ RUN npm install
6
+ COPY frontend/ .
7
+ # Set API base to empty so it uses relative paths (handled by Nginx)
8
+ ENV NEXT_PUBLIC_API_BASE=""
9
+ RUN npm run build
10
+
11
+ # Final Image
12
+ FROM python:3.12-slim
13
+ WORKDIR /app
14
+
15
+ # Install Node.js (for running frontend in dev/ssr mode) and Nginx
16
+ RUN apt-get update && apt-get install -y \
17
+ curl \
18
+ nginx \
19
+ && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
20
+ && apt-get install -y nodejs \
21
+ && rm -rf /var/lib/apt/lists/*
22
+
23
+ # Copy Backend
24
+ COPY backend/requirements.txt ./backend/
25
+ RUN pip install --no-cache-dir -r backend/requirements.txt
26
+ # Install missing deps found earlier
27
+ RUN pip install --no-cache-dir sqlalchemy==2.0.49 pymysql cryptography
28
+
29
+ COPY backend/ ./backend/
30
+
31
+ # Copy Frontend Build
32
+ COPY --from=frontend-builder /app/frontend/.next ./frontend/.next
33
+ COPY --from=frontend-builder /app/frontend/public ./frontend/public
34
+ COPY --from=frontend-builder /app/frontend/package.json ./frontend/package.json
35
+ COPY --from=frontend-builder /app/frontend/node_modules ./frontend/node_modules
36
+
37
+ # Nginx Config
38
+ COPY nginx.conf /etc/nginx/sites-available/default
39
+
40
+ # Start Script
41
+ COPY start.sh .
42
+ RUN chmod +x start.sh
43
+
44
+ # Expose HF Port
45
+ EXPOSE 7860
46
+
47
+ CMD ["./start.sh"]
nginx.conf ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ server {
2
+ listen 7860;
3
+ server_name localhost;
4
+
5
+ location / {
6
+ proxy_pass http://localhost:3000;
7
+ proxy_http_version 1.1;
8
+ proxy_set_header Upgrade $http_upgrade;
9
+ proxy_set_header Connection 'upgrade';
10
+ proxy_set_header Host $host;
11
+ proxy_cache_bypass $http_upgrade;
12
+ }
13
+
14
+ location /api {
15
+ proxy_pass http://localhost:8000/api;
16
+ proxy_set_header Host $host;
17
+ proxy_set_header X-Real-IP $remote_addr;
18
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
+ proxy_set_header X-Forwarded-Proto $scheme;
20
+ }
21
+
22
+ location /health {
23
+ proxy_pass http://localhost:8000/health;
24
+ proxy_set_header Host $host;
25
+ }
26
+ }
start.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Start Backend
4
+ cd /app/backend && uvicorn app.main:app --host 0.0.0.0 --port 8000 &
5
+
6
+ # Start Frontend
7
+ cd /app/frontend && npm run start -- -p 3000 &
8
+
9
+ # Start Nginx
10
+ nginx -g "daemon off;"