File size: 1,624 Bytes
9d29748
 
 
 
 
 
 
 
 
 
 
f30fe4c
9d29748
f30fe4c
9d29748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ── Stage 1: Build Frontend ──────────────────────────────────────────────
FROM node:20-slim AS frontend-build
WORKDIR /build
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci --no-audit --no-fund
COPY frontend/ ./
RUN npm run build

# ── Stage 2: Final Image ────────────────────────────────────────────────
FROM python:3.11-slim

# Install nginx, supervisor, and libgomp (required by LightGBM)
RUN apt-get update && \
    apt-get install -y --no-install-recommends nginx supervisor libgomp1 && \
    rm -rf /var/lib/apt/lists/* && \
    mkdir -p /var/log/supervisor

WORKDIR /app

# Install Python dependencies
COPY backend/requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt supervisor

# Copy backend code
COPY backend/app ./app

# Copy built frontend
COPY --from=frontend-build /build/dist /app/frontend/dist

# Copy configs
COPY nginx.conf /etc/nginx/nginx.conf
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Create non-root user (HF Spaces requirement)
RUN useradd -m -u 1000 appuser && \
    chown -R appuser:appuser /app && \
    chown -R appuser:appuser /var/log/nginx && \
    chown -R appuser:appuser /var/lib/nginx && \
    chown -R appuser:appuser /var/log/supervisor && \
    touch /run/nginx.pid && \
    chown appuser:appuser /run/nginx.pid

USER appuser

EXPOSE 7860

CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]