File size: 3,644 Bytes
34367da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# WidgeTDC Backend - GPU-Enabled Production Dockerfile
# Optimized for Hugging Face Spaces with NVIDIA GPU support

FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS base

# Install Node.js 20.x
RUN apt-get update && apt-get install -y \

    curl \
    git \
    python3 \
    python3-pip \
    build-essential \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install Python dependencies for GPU-accelerated embeddings
RUN pip3 install --no-cache-dir \

    torch==2.1.0 \
    transformers==4.35.0 \
    sentence-transformers==2.2.2 \
    accelerate==0.24.0

# Copy package files
COPY package*.json ./
COPY apps/backend/package*.json ./apps/backend/
COPY packages/domain-types/package*.json ./packages/domain-types/
COPY packages/mcp-types/package*.json ./packages/mcp-types/

# Install Node dependencies
RUN npm ci --include=dev --legacy-peer-deps

# Copy source code
COPY packages/ ./packages/
COPY apps/backend/ ./apps/backend/

# Build shared packages
RUN npm run build:domain-types || true
RUN npm run build:mcp-types || true

# Generate Prisma client
RUN cd apps/backend && npx prisma generate

# Build backend
RUN cd apps/backend && npm run build

# Production stage
FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS production

# Install Node.js and Python runtime
RUN apt-get update && apt-get install -y \

    curl \
    python3 \
    python3-pip \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install Python runtime dependencies
RUN pip3 install --no-cache-dir \

    torch==2.1.0 \
    transformers==4.35.0 \
    sentence-transformers==2.2.2 \
    accelerate==0.24.0

# Copy package files
COPY package*.json ./
COPY apps/backend/package*.json ./apps/backend/
COPY packages/domain-types/package*.json ./packages/domain-types/
COPY packages/mcp-types/package*.json ./packages/mcp-types/

# Install production dependencies
RUN npm ci --omit=dev --ignore-scripts --legacy-peer-deps

# Copy Prisma schema and client
COPY --from=base /app/apps/backend/prisma ./apps/backend/prisma
COPY --from=base /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=base /app/node_modules/@prisma ./node_modules/@prisma

# Copy built artifacts
COPY --from=base /app/packages/domain-types/dist ./packages/domain-types/dist
COPY --from=base /app/packages/mcp-types/dist ./packages/mcp-types/dist
COPY --from=base /app/apps/backend/dist ./apps/backend/dist

# Copy package.json for ESM resolution
COPY --from=base /app/packages/domain-types/package.json ./packages/domain-types/
COPY --from=base /app/packages/mcp-types/package.json ./packages/mcp-types/

# GPU Configuration
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
ENV CUDA_VISIBLE_DEVICES=0

# App Configuration
ENV NODE_ENV=production
ENV PORT=7860
ENV USE_GPU=true
ENV TRANSFORMERS_CACHE=/app/.cache
ENV HF_HOME=/app/.cache

# Hugging Face Spaces uses port 7860
EXPOSE 7860

WORKDIR /app/apps/backend

# Copy entrypoint script
COPY apps/backend/docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \

    CMD node -e "require('http').get('http://localhost:7860/health', (r) => r.statusCode === 200 ? process.exit(0) : process.exit(1))"

# Run migrations and start app
ENTRYPOINT ["/app/docker-entrypoint.sh"]