File size: 1,916 Bytes
b24d6d6
 
 
 
0ac45de
b24d6d6
 
 
 
 
 
 
 
 
 
 
0ac45de
b24d6d6
 
 
 
 
 
 
0ac45de
 
 
b24d6d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ac45de
b24d6d6
 
 
 
 
 
 
 
0ac45de
b24d6d6
0ac45de
b24d6d6
0ac45de
b24d6d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# ============================================
# MiroFish - HuggingFace Spaces Production Build
# Multi-stage: Vue frontend build + Python backend + nginx
# ============================================

# --- Stage 1: Build Vue.js frontend ---
FROM node:20-alpine AS frontend-build

WORKDIR /build/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci

COPY frontend/ ./
# Set empty base URL so production build uses relative URLs (nginx proxies to Flask)
ENV VITE_API_BASE_URL=""
RUN npm run build

# --- Stage 2: Production runtime ---
FROM python:3.11-slim

# Install nginx and required system packages
RUN apt-get update \
    && apt-get install -y --no-install-recommends nginx curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install Python dependencies (CPU-only torch to save ~1.5GB)
COPY backend/requirements.txt ./backend/requirements.txt
RUN pip install --no-cache-dir \
    --extra-index-url https://download.pytorch.org/whl/cpu \
    -r backend/requirements.txt

# Copy backend source
COPY backend/ ./backend/

# Copy built Vue frontend to nginx serve directory
COPY --from=frontend-build /build/frontend/dist /usr/share/nginx/html

# Copy deployment configs
COPY deploy/nginx.conf /etc/nginx/nginx.conf
COPY deploy/start.sh /app/start.sh
RUN chmod +x /app/start.sh

# Create uploads directory for simulation data
RUN mkdir -p /app/backend/uploads/projects \
    /app/backend/uploads/simulations \
    /app/backend/uploads/reports

# HuggingFace Spaces requires user with uid 1000
RUN useradd -m -u 1000 appuser \
    && chown -R appuser:appuser /app \
    && chown -R appuser:appuser /usr/share/nginx/html \
    && chown -R appuser:appuser /var/log/nginx \
    && chown -R appuser:appuser /var/lib/nginx \
    && chown -R appuser:appuser /etc/nginx \
    && touch /run/nginx.pid && chown appuser:appuser /run/nginx.pid

USER appuser

EXPOSE 7860

CMD ["/app/start.sh"]