File size: 2,599 Bytes
23b413b | 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 | # =============================================================================
# HomePilot β Hugging Face Spaces Dockerfile
# =============================================================================
# Three-stage build:
# 1. Build React frontend (Vite)
# 2. Runtime: Ollama + FastAPI + pre-built frontend + Chata personas
#
# HF Spaces constraints:
# - Must listen on port 7860
# - Only /tmp is writable at runtime
# - Free tier: 2 vCPU, 16GB RAM, no GPU
# =============================================================================
# ββ Stage 1: Frontend build ββββββββββββββββββββββββββββββ
FROM node:20-alpine AS frontend
WORKDIR /build
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install --no-audit --no-fund 2>/dev/null
COPY frontend/ ./
ENV VITE_API_URL=""
RUN npm run build && ls -la dist/
# ββ Stage 2: Runtime βββββββββββββββββββββββββββββββββββββ
FROM python:3.11-slim
# System deps + Ollama
RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates procps zstd \
&& rm -rf /var/lib/apt/lists/* \
&& curl -fsSL https://ollama.com/install.sh | sh
# HF Spaces user (uid 1000)
RUN useradd -m -u 1000 hpuser && \
mkdir -p /app /tmp/ollama /tmp/homepilot/data \
/tmp/homepilot/uploads /tmp/homepilot/outputs && \
chown -R hpuser:hpuser /app /tmp/ollama /tmp/homepilot
WORKDIR /app
# Python deps (cached layer)
COPY backend/requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Backend source
COPY backend/app ./app
# Ensure __init__.py exists (created by deploy script)
RUN touch ./app/__init__.py
# Community persona samples
COPY community/sample ./community/sample
# Chata personas (pre-installed)
COPY deploy/huggingface-space/chata-personas ./chata-personas
# Pre-built frontend from stage 1
COPY --from=frontend /build/dist ./frontend
# HF Space wrapper (serves frontend + patches config)
COPY deploy/huggingface-space/hf_wrapper.py ./hf_wrapper.py
COPY deploy/huggingface-space/auto_import_personas.py ./auto_import_personas.py
COPY deploy/huggingface-space/chata_project_bootstrap.py ./chata_project_bootstrap.py
# Startup script (copied to root by deploy script)
COPY start.sh ./start.sh
RUN chmod +x start.sh
USER hpuser
EXPOSE 7860
HEALTHCHECK --interval=30s --timeout=5s --start-period=90s --retries=3 \
CMD curl -fsS http://127.0.0.1:7860/health || exit 1
CMD ["./start.sh"]
|