Spaces:
Paused
Paused
| # 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"] | |