Anurag commited on
Commit
0975e23
·
unverified ·
2 Parent(s): 1ef6fa2f24e27d

improve Chromium/file detection and runtime install

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -0
  2. start.sh +43 -1
Dockerfile CHANGED
@@ -21,6 +21,7 @@ ENV DEV_MODE=${DEV_MODE}
21
  RUN apt-get update && apt-get install -y \
22
  git \
23
  sudo \
 
24
  ca-certificates \
25
  jq \
26
  curl \
 
21
  RUN apt-get update && apt-get install -y \
22
  git \
23
  sudo \
24
+ file \
25
  ca-certificates \
26
  jq \
27
  curl \
start.sh CHANGED
@@ -521,6 +521,40 @@ inject_provider_models_from_env "github-copilot" "GITHUB_COPILOT_MODELS" "COPILO
521
  # Browser configuration (managed local Chromium in HF/Docker)
522
  BROWSER_EXECUTABLE_PATH=""
523
  BROWSER_WRAPPER_PATH=""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
524
  # On Debian/Ubuntu, /usr/bin/chromium is often a shell wrapper while the real
525
  # ELF binary lives under /usr/lib/chromium/*. Prefer a real ELF binary, then
526
  # fall back to wrapper launchers (Playwright/OpenClaw can execute those too).
@@ -531,7 +565,13 @@ for candidate in \
531
  /usr/bin/chromium-browser \
532
  /snap/bin/chromium; do
533
  if [ -x "$candidate" ]; then
534
- if file "$candidate" 2>/dev/null | grep -q "ELF"; then
 
 
 
 
 
 
535
  BROWSER_EXECUTABLE_PATH="$candidate"
536
  break
537
  fi
@@ -543,6 +583,8 @@ done
543
  if [ -z "$BROWSER_EXECUTABLE_PATH" ] && [ -n "$BROWSER_WRAPPER_PATH" ]; then
544
  BROWSER_EXECUTABLE_PATH="$BROWSER_WRAPPER_PATH"
545
  echo "No ELF Chromium binary found; using launcher wrapper at $BROWSER_EXECUTABLE_PATH"
 
 
546
  fi
547
  if [ -z "$BROWSER_EXECUTABLE_PATH" ]; then
548
  echo "Warning: Chromium executable not found. Browser plugin will be disabled."
 
521
  # Browser configuration (managed local Chromium in HF/Docker)
522
  BROWSER_EXECUTABLE_PATH=""
523
  BROWSER_WRAPPER_PATH=""
524
+ HAS_FILE_CMD=false
525
+ if command -v file >/dev/null 2>&1; then
526
+ HAS_FILE_CMD=true
527
+ fi
528
+
529
+ ensure_chromium_for_browser_plugin() {
530
+ # Enforce Chromium availability when browser plugin is explicitly enabled.
531
+ [ "$BROWSER_PLUGIN_MODE" = "enabled" ] || return 0
532
+ for candidate in /usr/lib/chromium/chromium /usr/bin/chromium /usr/bin/chromium-browser; do
533
+ [ -x "$candidate" ] && return 0
534
+ done
535
+ if [ "$HAS_FILE_CMD" != "true" ]; then
536
+ echo "BROWSER_PLUGIN_MODE=enabled and 'file' command is missing; attempting runtime install..."
537
+ if _hc_apt_install file; then
538
+ HAS_FILE_CMD=true
539
+ echo "'file' command installed via apt-get."
540
+ else
541
+ echo "Warning: could not install 'file'; continuing with executable-path fallback checks."
542
+ fi
543
+ fi
544
+ echo "BROWSER_PLUGIN_MODE=enabled but Chromium is missing; attempting runtime install..."
545
+ if _hc_apt_install chromium; then
546
+ echo "Chromium installed via apt-get."
547
+ return 0
548
+ fi
549
+ if _hc_apt_install chromium-browser; then
550
+ echo "Chromium browser package installed via apt-get."
551
+ return 0
552
+ fi
553
+ echo "ERROR: Browser plugin is enabled, but Chromium install failed. Disable browser plugin or rebuild image with Chromium preinstalled." >&2
554
+ return 1
555
+ }
556
+ ensure_chromium_for_browser_plugin || HC_STARTUP_FAILURES=$((HC_STARTUP_FAILURES + 1))
557
+
558
  # On Debian/Ubuntu, /usr/bin/chromium is often a shell wrapper while the real
559
  # ELF binary lives under /usr/lib/chromium/*. Prefer a real ELF binary, then
560
  # fall back to wrapper launchers (Playwright/OpenClaw can execute those too).
 
565
  /usr/bin/chromium-browser \
566
  /snap/bin/chromium; do
567
  if [ -x "$candidate" ]; then
568
+ if [ "$HAS_FILE_CMD" = "true" ]; then
569
+ if file "$candidate" 2>/dev/null | grep -q "ELF"; then
570
+ BROWSER_EXECUTABLE_PATH="$candidate"
571
+ break
572
+ fi
573
+ else
574
+ # Minimal images may not ship `file`; accept the first executable path.
575
  BROWSER_EXECUTABLE_PATH="$candidate"
576
  break
577
  fi
 
583
  if [ -z "$BROWSER_EXECUTABLE_PATH" ] && [ -n "$BROWSER_WRAPPER_PATH" ]; then
584
  BROWSER_EXECUTABLE_PATH="$BROWSER_WRAPPER_PATH"
585
  echo "No ELF Chromium binary found; using launcher wrapper at $BROWSER_EXECUTABLE_PATH"
586
+ elif [ -n "$BROWSER_EXECUTABLE_PATH" ] && [ "$HAS_FILE_CMD" != "true" ]; then
587
+ echo "Detected Chromium executable at $BROWSER_EXECUTABLE_PATH (ELF probe skipped: 'file' command not installed)"
588
  fi
589
  if [ -z "$BROWSER_EXECUTABLE_PATH" ]; then
590
  echo "Warning: Chromium executable not found. Browser plugin will be disabled."