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