File size: 1,665 Bytes
d1d41c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Stage 1: Build the Next.js frontend
FROM node:20-alpine AS builder

WORKDIR /app
COPY package*.json ./
RUN npm install

COPY . .
# We need to ensure that the Next.js app knows the API URL during build/runtime
# For this Hugging Face setup with NGINX, the API is available at the same domain under /api/
ENV NEXT_PUBLIC_API_URL=/api
RUN npm run build

# Stage 2: Setup Python environment and run both applications
FROM python:3.11-slim

WORKDIR /app

# Install Node.js, NGINX, and Supervisord
RUN apt-get update && apt-get install -y \
    curl \
    nginx \
    supervisor \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

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

# Copy built frontend from the builder stage
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules

# Copy the rest of the frontend (e.g. next.config.ts) and the backend
COPY . /app

# Copy Nginx configuration
COPY nginx.conf /etc/nginx/sites-available/default

# Copy Supervisor configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Expose the port Hugging Face Spaces expects
EXPOSE 7860

# We set the environment variables for runtime
ENV PORT=3000
ENV NEXT_PUBLIC_API_URL=/api

# Start Supervisor, which will manage Next.js, FastAPI, and NGINX
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]