Spaces:
Running
Running
fix: resolve Gemini CLI relaunch failure by invoking entry JS directly with node flags
Browse files- Dockerfile +33 -9
Dockerfile
CHANGED
|
@@ -69,15 +69,39 @@ RUN for cmd in claude codex; do \
|
|
| 69 |
fi; \
|
| 70 |
done
|
| 71 |
|
| 72 |
-
# Gemini wrapper
|
| 73 |
-
#
|
| 74 |
-
#
|
| 75 |
-
#
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Install Python dependencies for sync
|
| 83 |
RUN pip install --no-cache-dir --break-system-packages huggingface_hub PyYAML
|
|
|
|
| 69 |
fi; \
|
| 70 |
done
|
| 71 |
|
| 72 |
+
# Gemini wrapper — definitive fix for "Failed to relaunch the CLI process":
|
| 73 |
+
#
|
| 74 |
+
# ROOT CAUSE: Gemini CLI checks process.execArgv for --max-old-space-size.
|
| 75 |
+
# NODE_OPTIONS does NOT populate process.execArgv, so Gemini always tries to
|
| 76 |
+
# relaunch itself with the flag as a CLI arg. That spawn fails in HF Spaces.
|
| 77 |
+
#
|
| 78 |
+
# FIX: Resolve the actual JS entry point at build time and invoke it directly
|
| 79 |
+
# via `node --max-old-space-size=4096 <entry.js>` so the flag IS in execArgv.
|
| 80 |
+
# Gemini sees it, skips the relaunch entirely.
|
| 81 |
+
#
|
| 82 |
+
# Also bake in headless env vars so they survive even when Paperclip spawns
|
| 83 |
+
# gemini with a custom env object (no env inheritance fallback):
|
| 84 |
+
# GEMINI_SANDBOX=false — skip Docker-sandbox attempt in containers
|
| 85 |
+
# GEMINI_CLI_TRUST_WORKSPACE=true — skip interactive workspace-trust prompt
|
| 86 |
+
RUN GEMINI_PKG="/usr/local/lib/node_modules/@google/gemini-cli" && \
|
| 87 |
+
GEMINI_JS=$(node -e " \
|
| 88 |
+
const pkg = require('$GEMINI_PKG/package.json'); \
|
| 89 |
+
const bin = pkg.bin; \
|
| 90 |
+
const entry = typeof bin === 'string' ? bin : (bin.gemini || bin[Object.keys(bin)[0]]); \
|
| 91 |
+
console.log(require('path').resolve('$GEMINI_PKG', entry)); \
|
| 92 |
+
") && \
|
| 93 |
+
echo "Gemini JS entry: $GEMINI_JS" && \
|
| 94 |
+
mv /usr/local/bin/gemini /usr/local/bin/gemini-real && \
|
| 95 |
+
{ \
|
| 96 |
+
echo '#!/bin/sh'; \
|
| 97 |
+
echo 'unset NODE_OPTIONS'; \
|
| 98 |
+
echo 'export NODE_OPTIONS="--no-deprecation --no-warnings"'; \
|
| 99 |
+
echo 'export GEMINI_SANDBOX=false'; \
|
| 100 |
+
echo 'export GEMINI_CLI_TRUST_WORKSPACE=true'; \
|
| 101 |
+
echo "exec node --max-old-space-size=4096 $GEMINI_JS \"\$@\""; \
|
| 102 |
+
} > /usr/local/bin/gemini && \
|
| 103 |
+
chmod +x /usr/local/bin/gemini && \
|
| 104 |
+
echo "=== gemini wrapper ===" && cat /usr/local/bin/gemini
|
| 105 |
|
| 106 |
# Install Python dependencies for sync
|
| 107 |
RUN pip install --no-cache-dir --break-system-packages huggingface_hub PyYAML
|