File size: 2,965 Bytes
61d29fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Multi-stage build for Hugging Face Spaces
# Runs all three apps: Docusaurus docs, React frontend, FastAPI backend

FROM node:20-slim AS docs-builder
WORKDIR /build

# Set baseUrl to /docs/ for HuggingFace deployment  # Docs are served at nginx /docs/ location
# routeBasePath: '/' in docusaurus.config.ts prevents /docs/docs/ nesting
ENV DOCUSAURUS_BASE_URL=/docs/

COPY website/package*.json ./
RUN npm config set fetch-retry-mintimeout 20000 && \
    npm config set fetch-retry-maxtimeout 120000 && \
    npm ci --prefer-offline --no-audit || npm install --prefer-offline --no-audit

# Add cache-busting argument to force rebuild when needed
ARG CACHE_BUST=2026-04-27-12-00-fix-double-docs-prefix

COPY website/ ./

# Verify environment variable is set and build
RUN echo "Building Docusaurus with DOCUSAURUS_BASE_URL=$DOCUSAURUS_BASE_URL" && \
    echo "Cache bust: 2026-04-27-12-00-fix-double-docs-prefix" && \
    npm run build && \
    echo "Verifying baseUrl in build output..." && \
    grep -r "baseUrl" build/ | head -5 || true

FROM python:3.11-slim

# Install system dependencies, nginx, and Node.js for frontend build
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    git \
    tesseract-ocr \
    nginx \
    supervisor \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy Python requirements and install
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# OPTIMIZATION: Copy frontend package files first for better caching
COPY frontend/package*.json /app/frontend/
RUN cd /app/frontend && npm ci

# Copy application code (now npm ci layer is cached)
COPY . .

# Copy built static files from docs stage
COPY --from=docs-builder /build/build /app/static/docs

# Build frontend (npm_modules already cached from above)
# Set production environment variables for Vite
ENV VITE_CANONICAL_DOMAIN=www.communityone.com
ENV VITE_API_URL=/api
# Cache bust: 2026-04-29-remove-axios
ARG CACHE_BUST_FRONTEND=2026-04-29-remove-axios
RUN cd /app/frontend && echo "Frontend build cache bust: $CACHE_BUST_FRONTEND" && npm run build

# Frontend is already built to /app/api/static/ via vite.config.ts
# Create frontend directory in /app/static for nginx
RUN mkdir -p /app/static/frontend && \
    ls -la /app/api/static/ && \
    cp -r /app/api/static/* /app/static/frontend/

# Create necessary directories
RUN mkdir -p /app/logs /app/data /var/log/supervisor

# Copy Hugging Face specific configs
COPY .huggingface/nginx.conf /etc/nginx/nginx.conf
COPY .huggingface/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY .huggingface/start.sh /app/start.sh
RUN chmod +x /app/start.sh

# Expose port 7860 (Hugging Face Spaces default)
EXPOSE 7860

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV LOG_LEVEL=INFO
ENV HF_SPACES=1

# Use supervisor to run all services
CMD ["/app/start.sh"]