# ============================================================================= # 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"]