File size: 1,536 Bytes
19aaa42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da48be0
 
 
 
19aaa42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54007ac
19aaa42
 
 
 
 
 
 
 
 
 
 
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
FROM node:18 AS frontend-builder

# Set working directory for frontend
WORKDIR /app/frontend

# Copy frontend package files and install dependencies
COPY frontend/package*.json ./
RUN npm install

# Copy frontend source code and build
COPY frontend/ .
RUN npm run build

# Start with Python base image for final stage
FROM python:3.9-slim

WORKDIR /app

# Install system dependencies and Node.js
RUN apt-get update && apt-get install -y \
    curl \
    && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

# Create necessary directories and set permissions
RUN mkdir -p ./figures ./pdfs ./src/processed_markdown \
    && chown -R 1000:1000 /app

# Create a user with ID 1000 (required for Hugging Face Spaces)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=/app

# Copy and install Python requirements
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy frontend build from previous stage
COPY --chown=user --from=frontend-builder /app/frontend/.next ./.next
COPY --chown=user --from=frontend-builder /app/frontend/public ./public
COPY --chown=user --from=frontend-builder /app/frontend/package*.json ./

# Copy backend code
COPY --chown=user src/ ./src/

# Install frontend production dependencies
RUN npm install --production

# Copy start script
COPY --chown=user start.sh ./
RUN chmod +x start.sh

# Start both services
CMD ["./start.sh"]