Spaces:
Paused
Paused
File size: 3,924 Bytes
5a81b95 | 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 121 | # WidgeTDC Backend - GPU-Enabled Production Dockerfile
# Optimized for Hugging Face Spaces with NVIDIA GPU support
# BUILD_VERSION: 2024-12-11-v3
#
# NOTE: This Dockerfile is used by the HF deployment workflow.
# The build context is the hf-space/ directory created by the workflow.
FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS base
# Install Node.js 20.x and build dependencies
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
# CRITICAL: Upgrade pip FIRST to fix resolver bug (AssertionError in get_topological_weights)
RUN python3 -m pip install --upgrade pip setuptools wheel
# Install Python ML dependencies one by one to avoid resolver issues
RUN pip3 install --no-cache-dir torch==2.1.2
RUN pip3 install --no-cache-dir transformers==4.36.0
RUN pip3 install --no-cache-dir sentence-transformers==2.3.1
RUN pip3 install --no-cache-dir accelerate==0.25.0
# Copy all package files first for better caching
# Root package.json contains workspaces config
COPY package.json package-lock.json* ./
# Create directory structure and copy package files
RUN mkdir -p apps/backend packages/domain-types packages/mcp-types
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 all dependencies (including dev for building)
RUN npm install --legacy-peer-deps || npm install --legacy-peer-deps --force
# Copy source files
COPY packages/domain-types/ ./packages/domain-types/
COPY packages/mcp-types/ ./packages/mcp-types/
COPY apps/backend/ ./apps/backend/
COPY tsconfig.json ./
# Build shared packages
WORKDIR /app/packages/domain-types
RUN npm run build || echo "domain-types build skipped"
WORKDIR /app/packages/mcp-types
RUN npm run build || echo "mcp-types build skipped"
# Generate Prisma client and build backend
WORKDIR /app/apps/backend
RUN npx prisma generate || echo "Prisma generate skipped"
RUN npm run build
# Production stage - minimal runtime image
FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS production
# Install Node.js 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
# CRITICAL: Upgrade pip FIRST
RUN python3 -m pip install --upgrade pip setuptools wheel
# Install Python ML dependencies one by one
RUN pip3 install --no-cache-dir torch==2.1.2
RUN pip3 install --no-cache-dir transformers==4.36.0
RUN pip3 install --no-cache-dir sentence-transformers==2.3.1
RUN pip3 install --no-cache-dir accelerate==0.25.0
# Copy necessary files from build stage
COPY --from=base /app/package.json ./
COPY --from=base /app/node_modules ./node_modules
COPY --from=base /app/packages ./packages
COPY --from=base /app/apps/backend/dist ./apps/backend/dist
COPY --from=base /app/apps/backend/package.json ./apps/backend/
COPY --from=base /app/apps/backend/prisma ./apps/backend/prisma
# 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
# Create cache directory for models
RUN mkdir -p /app/.cache && chmod 777 /app/.cache
# Hugging Face Spaces requires port 7860
EXPOSE 7860
WORKDIR /app/apps/backend
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Start with GPU support enabled
CMD ["node", "--max-old-space-size=4096", "--expose-gc", "dist/index.js"]
|