bshepp commited on
Commit
98917ae
Β·
1 Parent(s): 34410a8

Fix HF Space build: standalone Next.js output, memory limit, disable telemetry

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -8
  2. space/start.sh +2 -2
  3. src/frontend/next.config.js +1 -0
Dockerfile CHANGED
@@ -3,21 +3,23 @@ FROM node:20-slim AS frontend-build
3
 
4
  WORKDIR /app/frontend
5
  COPY src/frontend/package.json src/frontend/package-lock.json* ./
6
- RUN npm install --frozen-lockfile 2>/dev/null || npm install
7
 
8
  COPY src/frontend/ ./
9
 
10
  # Build-time env: WebSocket and API go through the same origin via nginx
11
  ENV NEXT_PUBLIC_WS_URL=""
12
  ENV NEXT_PUBLIC_API_URL=""
 
13
 
14
- RUN npm run build
 
15
 
16
 
17
  # ── Stage 2: Production image ────────────────────────────────────
18
  FROM python:3.10-slim
19
 
20
- # System deps: nginx + node (for Next.js SSR)
21
  RUN apt-get update && apt-get install -y --no-install-recommends \
22
  nginx \
23
  curl \
@@ -46,13 +48,12 @@ RUN pip install --no-cache-dir \
46
  COPY src/backend/app/ ./app/
47
  COPY src/backend/data/ ./data/
48
 
49
- # ── Frontend built artifacts ─────────────────────────────────────
 
50
  WORKDIR /app/frontend
51
- COPY --from=frontend-build /app/frontend/.next ./.next
52
- COPY --from=frontend-build /app/frontend/node_modules ./node_modules
53
- COPY --from=frontend-build /app/frontend/package.json ./
54
  COPY --from=frontend-build /app/frontend/public ./public 2>/dev/null || true
55
- COPY src/frontend/next.config.js ./
56
 
57
  # ── Nginx config ─────────────────────────────────────────────────
58
  COPY space/nginx.conf /etc/nginx/nginx.conf
 
3
 
4
  WORKDIR /app/frontend
5
  COPY src/frontend/package.json src/frontend/package-lock.json* ./
6
+ RUN npm ci 2>/dev/null || npm install
7
 
8
  COPY src/frontend/ ./
9
 
10
  # Build-time env: WebSocket and API go through the same origin via nginx
11
  ENV NEXT_PUBLIC_WS_URL=""
12
  ENV NEXT_PUBLIC_API_URL=""
13
+ ENV NEXT_TELEMETRY_DISABLED=1
14
 
15
+ # Limit Node memory for constrained HF Space build environment
16
+ RUN NODE_OPTIONS=--max-old-space-size=1536 npm run build
17
 
18
 
19
  # ── Stage 2: Production image ────────────────────────────────────
20
  FROM python:3.10-slim
21
 
22
+ # System deps: nginx + node (for Next.js standalone server)
23
  RUN apt-get update && apt-get install -y --no-install-recommends \
24
  nginx \
25
  curl \
 
48
  COPY src/backend/app/ ./app/
49
  COPY src/backend/data/ ./data/
50
 
51
+ # ── Frontend standalone build ────────────────────────────────────
52
+ # Next.js standalone output: self-contained server, no node_modules needed
53
  WORKDIR /app/frontend
54
+ COPY --from=frontend-build /app/frontend/.next/standalone ./
55
+ COPY --from=frontend-build /app/frontend/.next/static ./.next/static
 
56
  COPY --from=frontend-build /app/frontend/public ./public 2>/dev/null || true
 
57
 
58
  # ── Nginx config ─────────────────────────────────────────────────
59
  COPY space/nginx.conf /etc/nginx/nginx.conf
space/start.sh CHANGED
@@ -13,10 +13,10 @@ uvicorn app.main:app \
13
  --timeout-keep-alive 300 \
14
  &
15
 
16
- # ── 2. Start Next.js frontend ──────────────────────────────────
17
  echo "[2/3] Starting Next.js frontend on :3000 ..."
18
  cd /app/frontend
19
- PORT=3000 node_modules/.bin/next start -p 3000 &
20
 
21
  # ── 3. Start nginx reverse proxy ───────────────────────────────
22
  echo "[3/3] Starting nginx on :7860 ..."
 
13
  --timeout-keep-alive 300 \
14
  &
15
 
16
+ # ── 2. Start Next.js frontend (standalone mode) ────────────────
17
  echo "[2/3] Starting Next.js frontend on :3000 ..."
18
  cd /app/frontend
19
+ PORT=3000 HOSTNAME=0.0.0.0 node server.js &
20
 
21
  # ── 3. Start nginx reverse proxy ───────────────────────────────
22
  echo "[3/3] Starting nginx on :7860 ..."
src/frontend/next.config.js CHANGED
@@ -1,5 +1,6 @@
1
  /** @type {import('next').NextConfig} */
2
  const nextConfig = {
 
3
  async rewrites() {
4
  return [
5
  {
 
1
  /** @type {import('next').NextConfig} */
2
  const nextConfig = {
3
+ output: "standalone",
4
  async rewrites() {
5
  return [
6
  {