setup.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. set -e
  3. # Hardcoded to use the Python interpreter from the OpenDevin runtime client
  4. OPENDEVIN_PYTHON_INTERPRETER=/opendevin/miniforge3/bin/python
  5. # check if OPENDEVIN_PYTHON_INTERPRETER exists and it is usable
  6. if [ -z "$OPENDEVIN_PYTHON_INTERPRETER" ] || [ ! -x "$OPENDEVIN_PYTHON_INTERPRETER" ]; then
  7. echo "OPENDEVIN_PYTHON_INTERPRETER is not usable. Please pull the latest Docker image!"
  8. exit 1
  9. fi
  10. # Install dependencies
  11. $OPENDEVIN_PYTHON_INTERPRETER -m pip install jupyterlab notebook jupyter_kernel_gateway
  12. source ~/.bashrc
  13. # ADD /opendevin/plugins to PATH to make `jupyter_cli` available
  14. echo 'export PATH=$PATH:/opendevin/plugins/jupyter' >> ~/.bashrc
  15. export PATH=/opendevin/plugins/jupyter:$PATH
  16. # Temporary add /opendevin/miniforge3/bin to PATH
  17. # will not persist after the end of the script
  18. # This fixes https://github.com/OpenDevin/OpenDevin/pull/2489#issuecomment-2223088169
  19. export PATH=/opendevin/miniforge3/bin:$PATH
  20. # if user name is `opendevin`, add '/home/opendevin/.local/bin' to PATH
  21. if [ "$USER" = "opendevin" ]; then
  22. echo 'export PATH=$PATH:/home/opendevin/.local/bin' >> ~/.bashrc
  23. echo "export OPENDEVIN_PYTHON_INTERPRETER=$OPENDEVIN_PYTHON_INTERPRETER" >> ~/.bashrc
  24. export PATH=$PATH:/home/opendevin/.local/bin
  25. export PIP_CACHE_DIR=$HOME/.cache/pip
  26. fi
  27. # if user name is `root`, add '/root/.local/bin' to PATH
  28. if [ "$USER" = "root" ]; then
  29. echo 'export PATH=$PATH:/root/.local/bin' >> ~/.bashrc
  30. echo "export OPENDEVIN_PYTHON_INTERPRETER=$OPENDEVIN_PYTHON_INTERPRETER" >> ~/.bashrc
  31. export PATH=$PATH:/root/.local/bin
  32. export PIP_CACHE_DIR=$HOME/.cache/pip
  33. fi
  34. # Run background process to start jupyter kernel gateway
  35. # write a bash function that finds a free port
  36. find_free_port() {
  37. local start_port="${1:-20000}"
  38. local end_port="${2:-65535}"
  39. for port in $(seq $start_port $end_port); do
  40. if ! ss -tuln | awk '{print $5}' | grep -q ":$port$"; then
  41. echo $port
  42. return
  43. fi
  44. done
  45. echo "No free ports found in the range $start_port to $end_port" >&2
  46. return 1
  47. }
  48. export JUPYTER_GATEWAY_PORT=$(find_free_port 20000 30000)
  49. $OPENDEVIN_PYTHON_INTERPRETER -m \
  50. jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=$JUPYTER_GATEWAY_PORT > /opendevin/logs/jupyter_kernel_gateway.log 2>&1 &
  51. export JUPYTER_GATEWAY_PID=$!
  52. echo "export JUPYTER_GATEWAY_PID=$JUPYTER_GATEWAY_PID" >> ~/.bashrc
  53. export JUPYTER_GATEWAY_KERNEL_ID="default"
  54. echo "export JUPYTER_GATEWAY_KERNEL_ID=$JUPYTER_GATEWAY_KERNEL_ID" >> ~/.bashrc
  55. echo "JupyterKernelGateway started with PID: $JUPYTER_GATEWAY_PID"
  56. # Start the jupyter_server
  57. export JUPYTER_EXEC_SERVER_PORT=$(find_free_port 30000 40000)
  58. echo "export JUPYTER_EXEC_SERVER_PORT=$JUPYTER_EXEC_SERVER_PORT" >> ~/.bashrc
  59. $OPENDEVIN_PYTHON_INTERPRETER /opendevin/plugins/jupyter/execute_server.py > /opendevin/logs/jupyter_execute_server.log 2>&1 &
  60. export JUPYTER_EXEC_SERVER_PID=$!
  61. echo "export JUPYTER_EXEC_SERVER_PID=$JUPYTER_EXEC_SERVER_PID" >> ~/.bashrc
  62. echo "Execution server started with PID: $JUPYTER_EXEC_SERVER_PID"
  63. # Wait until /opendevin/logs/jupyter_kernel_gateway.log contains "is available"
  64. while ! grep -q "at" /opendevin/logs/jupyter_kernel_gateway.log; do
  65. echo "Waiting for Jupyter kernel gateway to be available..."
  66. sleep 1
  67. done
  68. # Wait until /opendevin/logs/jupyter_execute_server.log contains "Jupyter kernel created for conversation"
  69. while ! grep -q "kernel created" /opendevin/logs/jupyter_execute_server.log; do
  70. echo "Waiting for Jupyter kernel to be created..."
  71. sleep 1
  72. done
  73. echo "Jupyter kernel ready."