TheQuantEd commited on
Commit
6b12e79
Β·
1 Parent(s): 59abb4f

Add Dockerfile to repo root for HuggingFace Spaces build

Browse files
Files changed (1) hide show
  1. Dockerfile +128 -0
Dockerfile ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ═══════════════════════════════════════════════════════════════════════════════
2
+ # ClinicalMatch AI β€” HuggingFace Spaces Dockerfile
3
+ # Single container: Neo4j Community + FastAPI + Next.js + Nginx (supervisord)
4
+ # Exposed port: 7860 (HF Spaces default)
5
+ # Persistent storage: /data (Neo4j data lives here β€” survives restarts)
6
+ # ═══════════════════════════════════════════════════════════════════════════════
7
+
8
+ # ── Stage 1: Build Next.js ────────────────────────────────────────────────────
9
+ FROM node:20-slim AS frontend-builder
10
+
11
+ WORKDIR /build/frontend
12
+
13
+ COPY frontend/package*.json ./
14
+ RUN npm install --legacy-peer-deps --prefer-offline
15
+
16
+ COPY frontend/ ./
17
+
18
+ # Build with empty API URL so all requests are relative (Nginx routes them)
19
+ ENV NEXT_PUBLIC_API_URL=""
20
+ RUN npm run build
21
+
22
+ # ── Stage 2: Final runtime image ──────────────────────────────────────────────
23
+ FROM ubuntu:22.04
24
+
25
+ ENV DEBIAN_FRONTEND=noninteractive
26
+ ENV LANG=C.UTF-8
27
+
28
+ # ── System dependencies ────────────────────────────────────────────────────────
29
+ RUN apt-get update && apt-get install -y --no-install-recommends \
30
+ # Java for Neo4j
31
+ openjdk-17-jre-headless \
32
+ # Python
33
+ python3.11 python3-pip python3.11-venv \
34
+ # Web / infra
35
+ nginx \
36
+ supervisor \
37
+ # Utilities
38
+ curl wget ca-certificates gnupg \
39
+ && rm -rf /var/lib/apt/lists/*
40
+
41
+ # ── Node.js 20 ────────────────────────────────────────────────────────────────
42
+ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
43
+ && apt-get install -y --no-install-recommends nodejs \
44
+ && rm -rf /var/lib/apt/lists/*
45
+
46
+ # ── Neo4j Community 5.x ───────────────────────────────────────────────────────
47
+ ENV NEO4J_VERSION=5.18.0
48
+ ENV NEO4J_HOME=/opt/neo4j
49
+ ENV PATH="${NEO4J_HOME}/bin:${PATH}"
50
+
51
+ ENV APOC_VERSION=5.18.0
52
+
53
+ RUN wget -q "https://dist.neo4j.org/neo4j-community-${NEO4J_VERSION}-unix.tar.gz" \
54
+ && tar -xzf "neo4j-community-${NEO4J_VERSION}-unix.tar.gz" -C /opt \
55
+ && mv "/opt/neo4j-community-${NEO4J_VERSION}" /opt/neo4j \
56
+ && rm "neo4j-community-${NEO4J_VERSION}-unix.tar.gz" \
57
+ && rm -rf /opt/neo4j/data # will be symlinked to /data at runtime
58
+
59
+ # Download APOC plugin (Community-compatible jar)
60
+ RUN wget -q \
61
+ "https://github.com/neo4j/apoc/releases/download/${APOC_VERSION}/apoc-${APOC_VERSION}-core.jar" \
62
+ -O /opt/neo4j/plugins/apoc-${APOC_VERSION}-core.jar
63
+
64
+ # Neo4j configuration β€” listen on all interfaces, use /data for persistence
65
+ RUN { \
66
+ echo "server.bolt.listen_address=0.0.0.0:7687"; \
67
+ echo "server.http.listen_address=0.0.0.0:7474"; \
68
+ echo "server.directories.data=/data/neo4j/data"; \
69
+ echo "server.directories.logs=/data/neo4j/logs"; \
70
+ echo "server.directories.plugins=/data/neo4j/plugins"; \
71
+ echo "dbms.security.auth_enabled=true"; \
72
+ echo "dbms.security.procedures.unrestricted=apoc.*"; \
73
+ echo "dbms.security.procedures.allowlist=apoc.*"; \
74
+ echo "server.memory.heap.initial_size=512m"; \
75
+ echo "server.memory.heap.max_size=1g"; \
76
+ echo "server.memory.pagecache.size=256m"; \
77
+ echo "db.transaction.timeout=60s"; \
78
+ echo "dbms.logs.query.enabled=OFF"; \
79
+ } >> /opt/neo4j/conf/neo4j.conf
80
+
81
+ # ── Python backend ────────────────────────────────────────────────────────────
82
+ WORKDIR /app/backend
83
+
84
+ COPY backend/requirements.txt .
85
+ RUN pip3 install --no-cache-dir -r requirements.txt
86
+
87
+ COPY backend/ .
88
+
89
+ # ── Next.js frontend (pre-built) ───────────────────────────────────────────────
90
+ WORKDIR /app/frontend
91
+
92
+ # Copy only what Next.js needs to run (not dev deps)
93
+ COPY --from=frontend-builder /build/frontend/.next/standalone ./
94
+ COPY --from=frontend-builder /build/frontend/.next/static ./.next/static
95
+ COPY --from=frontend-builder /build/frontend/public ./public
96
+
97
+ # ── Config files ───────────────────────────────────────────────────────────────
98
+ COPY docker/nginx.conf /app/docker/nginx.conf
99
+ COPY docker/supervisord.conf /app/docker/supervisord.conf
100
+ COPY docker/entrypoint.sh /app/docker/entrypoint.sh
101
+
102
+ RUN chmod +x /app/docker/entrypoint.sh
103
+
104
+ # ── Nginx writable dirs (runs without root after init) ────────────────────────
105
+ RUN mkdir -p /tmp/nginx-cache /tmp/nginx-body /tmp/nginx-run \
106
+ && chown -R www-data:www-data /var/log/nginx /var/lib/nginx 2>/dev/null || true
107
+
108
+ # ── Expose & environment ───────────────────────────────────────────────────────
109
+ EXPOSE 7860
110
+
111
+ # Neo4j β€” local Community instance (no Aura)
112
+ ENV NEO4J_URI=bolt://127.0.0.1:7687
113
+ ENV NEO4J_USERNAME=neo4j
114
+ ENV NEO4J_PASSWORD=clinicalmatch2024
115
+ ENV NEO4J_DATABASE=neo4j
116
+
117
+ # LLM β€” OpenAI-compatible (set real values via HF Spaces secrets)
118
+ ENV OPENAI_API_KEY=""
119
+ ENV OPENAI_BASE_URL=https://ai.aimlapi.com/v1
120
+ ENV OPENAI_MODEL=claude-opus-4-7
121
+
122
+ # Next.js standalone listens on 3000 internally; Nginx routes externally
123
+ ENV PORT=3000
124
+ ENV HOSTNAME=127.0.0.1
125
+
126
+ WORKDIR /app
127
+
128
+ ENTRYPOINT ["/app/docker/entrypoint.sh"]