openhands commited on
Commit
7cd90ad
·
1 Parent(s): 14c27ac

fix: make JupyterLab install conditional on DEV_MODE

Browse files

- Only install jupyterlab/tornado/ipywidgets when DEV_MODE=true during Docker build
- Only copy Jupyter login template when DEV_MODE is enabled
- Add runtime fallback in start.sh for failed builds
- This reduces image size and build time when dev mode is not needed

Files changed (2) hide show
  1. Dockerfile +13 -6
  2. start.sh +2 -2
Dockerfile CHANGED
@@ -49,12 +49,17 @@ RUN apt-get update && apt-get install -y \
49
  xfonts-scalable \
50
  --no-install-recommends && \
51
  pip3 install --no-cache-dir --break-system-packages huggingface_hub && \
52
- pip3 install --no-cache-dir --break-system-packages \
53
- jupyterlab==4.5.7 \
54
- tornado==6.5.5 \
55
- ipywidgets==8.1.8 && \
56
  rm -rf /var/lib/apt/lists/*
57
 
 
 
 
 
 
 
 
 
 
58
  # Reuse existing node user (UID 1000). Allow passwordless package-manager
59
  # commands only so runtime apt installs can be replayed after HF Space restarts.
60
  RUN mkdir -p /home/node/app /home/node/.openclaw && \
@@ -90,9 +95,11 @@ COPY --chown=1000:1000 wa-guardian.js /home/node/app/wa-guardian.js
90
  COPY --chown=1000:1000 cloudflare-keepalive-setup.py /home/node/app/cloudflare-keepalive-setup.py
91
  COPY --chown=1000:1000 openclaw-sync.py /home/node/app/openclaw-sync.py
92
  COPY --chown=1000:1000 multi-provider-key-rotator.cjs /home/node/app/multi-provider-key-rotator.cjs
 
 
93
  RUN printf '%s\n' \
94
  '#!/usr/bin/env bash' \
95
- 'set -euo pipefail' \
96
  'case "$(printf "%s" "${DEV_MODE}" | tr "[:upper:]" "[:lower:]")" in' \
97
  ' true|1|yes|on)' \
98
  " python3 -c \"from pathlib import Path; import shutil, jupyter_server; template_dir = Path(jupyter_server.__file__).parent / 'templates'; template_dir.mkdir(parents=True, exist_ok=True); shutil.copyfile('/home/node/app/login.html', template_dir / 'login.html')\"" \
@@ -100,7 +107,7 @@ RUN printf '%s\n' \
100
  'esac' \
101
  > /tmp/setup-jupyter-template.sh && \
102
  chmod +x /tmp/setup-jupyter-template.sh && \
103
- /tmp/setup-jupyter-template.sh && \
104
  rm -f /tmp/setup-jupyter-template.sh
105
  RUN chmod +x /home/node/app/start.sh \
106
  /home/node/app/cloudflare-proxy-setup.py \
 
49
  xfonts-scalable \
50
  --no-install-recommends && \
51
  pip3 install --no-cache-dir --break-system-packages huggingface_hub && \
 
 
 
 
52
  rm -rf /var/lib/apt/lists/*
53
 
54
+ # Install JupyterLab only when DEV_MODE is enabled (build-time)
55
+ # This avoids installing large packages when terminal is not needed
56
+ RUN if [ "${DEV_MODE}" = "true" ] || [ "${DEV_MODE}" = "1" ] || [ "${DEV_MODE}" = "yes" ] || [ "${DEV_MODE}" = "on" ]; then \
57
+ pip3 install --no-cache-dir --break-system-packages \
58
+ jupyterlab==4.5.7 \
59
+ tornado==6.5.5 \
60
+ ipywidgets==8.1.8; \
61
+ fi
62
+
63
  # Reuse existing node user (UID 1000). Allow passwordless package-manager
64
  # commands only so runtime apt installs can be replayed after HF Space restarts.
65
  RUN mkdir -p /home/node/app /home/node/.openclaw && \
 
95
  COPY --chown=1000:1000 cloudflare-keepalive-setup.py /home/node/app/cloudflare-keepalive-setup.py
96
  COPY --chown=1000:1000 openclaw-sync.py /home/node/app/openclaw-sync.py
97
  COPY --chown=1000:1000 multi-provider-key-rotator.cjs /home/node/app/multi-provider-key-rotator.cjs
98
+ # Copy Jupyter login template only when DEV_MODE is enabled
99
+ # This avoids import errors when JupyterLab is not installed
100
  RUN printf '%s\n' \
101
  '#!/usr/bin/env bash' \
102
+ 'set -u' \
103
  'case "$(printf "%s" "${DEV_MODE}" | tr "[:upper:]" "[:lower:]")" in' \
104
  ' true|1|yes|on)' \
105
  " python3 -c \"from pathlib import Path; import shutil, jupyter_server; template_dir = Path(jupyter_server.__file__).parent / 'templates'; template_dir.mkdir(parents=True, exist_ok=True); shutil.copyfile('/home/node/app/login.html', template_dir / 'login.html')\"" \
 
107
  'esac' \
108
  > /tmp/setup-jupyter-template.sh && \
109
  chmod +x /tmp/setup-jupyter-template.sh && \
110
+ /tmp/setup-jupyter-template.sh || echo "Jupyter template setup skipped" ; \
111
  rm -f /tmp/setup-jupyter-template.sh
112
  RUN chmod +x /home/node/app/start.sh \
113
  /home/node/app/cloudflare-proxy-setup.py \
start.sh CHANGED
@@ -749,10 +749,10 @@ if [ -n "${CLOUDFLARE_PROXY_URL:-}" ]; then
749
  echo "Proxy : ${CLOUDFLARE_PROXY_URL}"
750
  fi
751
  RUNTIME_JUPYTER_ENABLED="$DEV_MODE_ENABLED"
752
- # Add user bin to PATH for jupyter-lab (installed in Dockerfile build)
753
  export PATH="$HOME/.local/bin:$PATH"
754
 
755
- # Skip runtime install since jupyter is installed during build
756
  if [ "$DEV_MODE_ENABLED" = "true" ] && ! python3 -c "import jupyterlab" >/dev/null 2>&1; then
757
  echo "DEV_MODE enabled but jupyter-lab is missing; attempting runtime install..."
758
  if python3 -m pip install --user --no-cache-dir --break-system-packages jupyterlab==4.5.7 tornado==6.5.5 ipywidgets==8.1.8; then
 
749
  echo "Proxy : ${CLOUDFLARE_PROXY_URL}"
750
  fi
751
  RUNTIME_JUPYTER_ENABLED="$DEV_MODE_ENABLED"
752
+ # Add user bin to PATH for jupyter-lab (installed in Dockerfile when DEV_MODE=true)
753
  export PATH="$HOME/.local/bin:$PATH"
754
 
755
+ # Runtime install fallback: only attempt if DEV_MODE is enabled but install failed during build
756
  if [ "$DEV_MODE_ENABLED" = "true" ] && ! python3 -c "import jupyterlab" >/dev/null 2>&1; then
757
  echo "DEV_MODE enabled but jupyter-lab is missing; attempting runtime install..."
758
  if python3 -m pip install --user --no-cache-dir --break-system-packages jupyterlab==4.5.7 tornado==6.5.5 ipywidgets==8.1.8; then