kofdai commited on
Commit
ae875cf
·
verified ·
1 Parent(s): 0f5b0c9

Add Dockerfile for HuggingFace Spaces deployment

Browse files
Files changed (1) hide show
  1. Dockerfile +89 -0
Dockerfile ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Multi-stage build for NullAI Phi-4 Knowledge System
2
+ # Optimized for HuggingFace Spaces deployment
3
+
4
+ # Stage 1: Build frontend
5
+ FROM node:18-alpine AS frontend-builder
6
+
7
+ WORKDIR /app/frontend
8
+
9
+ # Copy package files
10
+ COPY frontend/package*.json ./
11
+
12
+ # Install dependencies
13
+ RUN npm ci --only=production
14
+
15
+ # Copy frontend source
16
+ COPY frontend/ ./
17
+
18
+ # Build frontend
19
+ RUN npm run build
20
+
21
+ # Stage 2: Python backend
22
+ FROM python:3.11-slim
23
+
24
+ LABEL maintainer="Kodai Motonishi <kodai820820@gmail.com>"
25
+ LABEL description="NullAI Phi-4 14B Knowledge Management System"
26
+
27
+ WORKDIR /app
28
+
29
+ # Install system dependencies
30
+ RUN apt-get update && apt-get install -y \
31
+ gcc \
32
+ g++ \
33
+ make \
34
+ curl \
35
+ && rm -rf /var/lib/apt/lists/*
36
+
37
+ # Copy backend requirements
38
+ COPY backend/requirements.txt ./backend/
39
+
40
+ # Install Python dependencies
41
+ RUN pip install --no-cache-dir --upgrade pip && \
42
+ pip install --no-cache-dir -r backend/requirements.txt
43
+
44
+ # Copy backend code
45
+ COPY backend/ ./backend/
46
+
47
+ # Copy frontend build from previous stage
48
+ COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
49
+
50
+ # Copy configuration files
51
+ COPY models_config.json domains_config.json null_ai_config.json* ./
52
+
53
+ # Copy utility scripts (optional)
54
+ COPY db_manager.py* inference_engine_unified.py* runner_engine.py* ./ || true
55
+
56
+ # Copy import tools
57
+ COPY import_iath.py batch_import_iath.sh ./
58
+
59
+ # Create necessary directories
60
+ RUN mkdir -p /app/data /app/uploads
61
+
62
+ # Set environment variables for HuggingFace Spaces
63
+ ENV PYTHONPATH=/app
64
+ ENV PYTHONUNBUFFERED=1
65
+ ENV HOST=0.0.0.0
66
+ ENV PORT=7860
67
+
68
+ # Database configuration
69
+ ENV DATABASE_URL=sqlite:////app/data/nullai_knowledge.db
70
+
71
+ # Security settings
72
+ ENV SECRET_KEY=changeme-in-production
73
+
74
+ # CORS settings (will be updated in Spaces)
75
+ ENV CORS_ORIGINS='["https://kofdai-nullai-knowledge-system.hf.space"]'
76
+
77
+ # Expose port (HuggingFace Spaces standard)
78
+ EXPOSE 7860
79
+
80
+ # Health check
81
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
82
+ CMD curl -f http://localhost:7860/api/system/health || exit 1
83
+
84
+ # Initialize database and start application
85
+ CMD python backend/create_db.py && \
86
+ uvicorn backend.app.main:app \
87
+ --host 0.0.0.0 \
88
+ --port 7860 \
89
+ --log-level info