File size: 2,215 Bytes
5301c48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
# Multi-stage build for combined frontend + backend
FROM node:18-alpine AS frontend-builder

WORKDIR /app

# Copy package files
COPY web/package*.json ./

# Install dependencies
RUN npm ci

# Copy frontend code and build
COPY web/ ./

# Clean up unnecessary files
RUN rm -rf api/ || true
RUN rm -rf storage/ || true
RUN rm -rf .git/ || true
RUN rm -rf .next/ || true
RUN rm -rf .local/ || true

# Build frontend
RUN npm run build

# Backend stage
FROM python:3.11-slim

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

# Install Node.js for combined container
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get install -y nodejs

WORKDIR /app

# Copy pyproject.toml and poetry.lock
COPY pyproject.toml poetry.lock ./

# Install Poetry and basic dependencies (skip heavy ML packages for testing)
RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir poetry \
    && poetry config virtualenvs.create false \
    && poetry install --only=main --no-root || pip install fastapi uvicorn python-dotenv pydantic

# Copy starfish source code and README (needed by backend)
COPY src/ ./src/
COPY README.md ./

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

# Copy backend API code
COPY web/api/ ./web/api/

# Copy configuration files
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY nginx.conf /etc/nginx/nginx.conf

# Create necessary directories and set permissions
RUN mkdir -p /var/log/supervisor /var/log/nginx /var/run \
    && chmod +x /app/src/ || true

# Expose port 7860 (required for Hugging Face Spaces)
EXPOSE 7860

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

# Start supervisor which manages both nginx and the applications
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]