Spaces:
Paused
Paused
File size: 2,323 Bytes
5df0bfe f332708 5df0bfe f332708 5df0bfe f332708 5df0bfe f332708 5eb4857 5df0bfe 5eb4857 36ba9e5 5df0bfe 5eb4857 f332708 5eb4857 5df0bfe 5eb4857 5df0bfe 1049d57 5df0bfe 1049d57 5df0bfe 1049d57 5eb4857 5df0bfe 5eb4857 1049d57 5eb4857 | 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 | # --- STAGE 1: FRONTEND BUILD (Node.js) ---
FROM node:20-slim AS frontend-builder
WORKDIR /app
# Increase memory for the JS builder to prevent "exit code: 2" crashes
ENV NODE_OPTIONS="--max-old-space-size=4096"
# Copy monorepo root config
COPY frontend/package*.json ./frontend/
COPY frontend/tsconfig.json ./frontend/
# Copy all packages and apps
COPY frontend/packages ./frontend/packages
COPY frontend/apps ./frontend/apps
WORKDIR /app/frontend
# Install and build sequentially (More reliable than --workspaces)
RUN npm install
RUN npm run build -w apps/customer
RUN npm run build -w apps/internal
# --- STAGE 2: BACKEND BASE (Python) ---
FROM python:3.11-slim AS base
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app
WORKDIR /app
# Install minimal system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
gcc \
curl \
ca-certificates \
redis-server \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Install core requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# --- STAGE 3: HEAVY-AI ---
FROM base AS heavy
COPY requirements-ai.txt .
RUN pip install --no-cache-dir -r requirements-ai.txt
# --- STAGE 4: PRODUCTION (Unified) ---
FROM heavy AS production
WORKDIR /app
# Create a non-privileged user and group
RUN groupadd -r nexus && useradd -r -g nexus -u 1000 nexus
# Create runtime directories and set ownership BEFORE copying code
RUN mkdir -p uploads logs && \
chown -R nexus:nexus /app
# Copy backend application code (Change ownership during copy)
COPY --chown=nexus:nexus . .
# Copy BUILT frontend assets from Stage 1 (Change ownership during copy)
COPY --chown=nexus:nexus --from=frontend-builder /app/frontend/apps/customer/dist ./frontend/apps/customer/dist
COPY --chown=nexus:nexus --from=frontend-builder /app/frontend/apps/internal/dist ./frontend/apps/internal/dist
# Ensure the app can write to the runtime directories
RUN chmod -R 775 uploads logs
# Expose Hugging Face default port
EXPOSE 7860
# Ensure entrypoint script is executable
RUN sed -i 's/\r$//' scripts/run_prod.sh && \
chmod +x scripts/run_prod.sh
# Switch to the non-root user
USER nexus
# Use the unified sidecar entrypoint
CMD ["./scripts/run_prod.sh"]
|