File size: 1,575 Bytes
d51321a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
# Multi-stage build for uvify HuggingFace app
FROM node:20-slim AS frontend-builder

# Set working directory for frontend build
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install Node.js dependencies
RUN npm ci

# Copy frontend source code
COPY src/ ./src/
COPY public/ ./public/
COPY index.html ./
COPY vite.config.ts ./
COPY tsconfig*.json ./
COPY tailwind.config.js ./
COPY postcss.config.js ./
COPY eslint.config.js ./

# Build the frontend for production
RUN npm run build

# Production stage
FROM python:3.10-slim

# Create a non-root user
RUN useradd --create-home --shell /bin/bash user

# Set working directory
WORKDIR /app

# Install system dependencies and uv
RUN apt-get update && apt-get install -y \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Install uv for fast Python package management
RUN pip install uv

# Copy frontend build from previous stage
COPY --chown=user --from=frontend-builder /app/dist ./static

# Copy Python backend files
COPY --chown=user server.py ./
COPY --chown=user requirements.txt ./

# Install Python dependencies using uv
RUN uv pip install --system -r requirements.txt

# Change ownership of the app directory to user
RUN chown -R user:user /app

# Switch to non-root user
USER user

# Expose port 7860 (HuggingFace default)
EXPOSE 7860

# Set environment variables
ENV PORT=7860
ENV PYTHONPATH=/app

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/docs || exit 1

# Run the production server
CMD ["python", "server.py"]