File size: 3,258 Bytes
9ca45c2
426134c
0ac6477
9ca45c2
 
 
 
 
 
426134c
9ca45c2
 
0ac6477
426134c
9ca45c2
 
 
0ac6477
9ca45c2
 
0ac6477
9ca45c2
 
0ac6477
 
 
 
 
 
426134c
 
0ac6477
 
 
 
 
 
 
 
 
 
426134c
 
0ac6477
 
 
 
9ca45c2
 
 
 
 
 
 
 
 
 
 
 
 
 
426134c
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
# =============================================================================
# Chat2API β€” Hugging Face Spaces Dockerfile
# Clones, builds, and runs on port 7860
# =============================================================================

FROM node:20-slim

# ── OS dependencies ───────────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
    git curl python3 make g++ ca-certificates \
  && rm -rf /var/lib/apt/lists/*

# ── node:20-slim already has uid=1000 as "node"; rename to "user" ─────────────
RUN usermod -l user -d /home/user -m node && groupmod -n user node

WORKDIR /app

# ── Clone source ──────────────────────────────────────────────────────────────
RUN git clone --depth=1 https://github.com/xiaoY233/Chat2API.git .

# ── Install all deps (dev included β€” needed for build) ────────────────────────
RUN npm ci --ignore-scripts

# ── Inject a fake "electron" package so electron-vite can compile the main ─────
# process without a real Electron binary or display server.
COPY electron-stub.js /app/node_modules/electron/index.js
COPY electron-stub-pkg.json /app/node_modules/electron/package.json

# ── Build with electron-vite (outputs to out/) ────────────────────────────────
RUN npx electron-vite build 2>&1 || true

# ── Also try renderer separately as fallback ──────────────────────────────────
RUN npx vite build --config vite.renderer.config.ts --outDir out/renderer 2>&1 || true

# ── Show what was built ───────────────────────────────────────────────────────
RUN find /app/out /app/dist -name "*.js" 2>/dev/null | head -30 || echo "No build output found"

# ── Write the runtime server entrypoint ───────────────────────────────────────
COPY server-entry.js /app/server.js

# ── Slim down ─────────────────────────────────────────────────────────────────
RUN npm prune --omit=dev 2>/dev/null || true && npm cache clean --force

# ── Re-inject stub after prune (prune may have wiped node_modules/electron) ───
COPY electron-stub.js /app/node_modules/electron/index.js
COPY electron-stub-pkg.json /app/node_modules/electron/package.json

RUN mkdir -p /app/.chat2api && chown -R user:user /app

USER user

ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PORT=7860 \
    PROXY_PORT=7860 \
    HEADLESS=true \
    NODE_ENV=production \
    CHAT2API_DATA_DIR=/app/.chat2api

EXPOSE 7860

CMD ["node", "/app/server.js"]