瀏覽代碼

完成环境变量 VSCODE_HOST 自定义

mrh 1 年之前
父節點
當前提交
f24bad60a2
共有 7 個文件被更改,包括 30 次插入61 次删除
  1. 2 2
      .env
  2. 0 2
      Dockerfile
  3. 1 1
      OpenHands
  4. 24 0
      dev.md
  5. 2 4
      docker-compose.yaml
  6. 0 51
      src/code-server-plugins.py
  7. 1 1
      src/config.toml

+ 2 - 2
.env

@@ -12,5 +12,5 @@ SANDBOX_USER_ID=1000
 # WORKSPACE_MOUNT_PATH=/home/mrh/program/openhands/testm/workspace
 WORKSPACE_MOUNT_PATH=/home/mrh/program/openhands/OpenHands
 VSCODE_HOST=sv-v2
-VSCODE_PORT=9806
-FILE_STORE_PATH=/home/mrh/program/openhands/cache/file_store
+# VSCODE_PORT=9806
+# FILE_STORE_PATH=/home/mrh/program/openhands/cache/file_store

+ 0 - 2
Dockerfile

@@ -13,5 +13,3 @@ COPY ./src/code-server-plugins.py /openhands/code/openhands/runtime/plugins/vsco
 ENV http_proxy=
 ENV https_proxy=
 ENV no_proxy=
-# sudo docker build -t all-hands-code-server:0.16-nikolaik .
-# dk run --name csruntime --rm -p 9806:9806 -v /home/mrh/program/openhands/testm:/home/mrh/program/openhands/testm all-hands-code-server:0.16-nikolaik bash -c "code-server --bind-addr 0.0.0.0:9806 --auth none /home/mrh/program/openhands/testm"

+ 1 - 1
OpenHands

@@ -1 +1 @@
-Subproject commit 642e962f89c4450d840369161860160750e9227b
+Subproject commit 56ff30cb3f8805a64b70b1e247ab7680182a3fe2

+ 24 - 0
dev.md

@@ -0,0 +1,24 @@
+# Runtime
+## 构建自己的 Runtime 镜像
+```shell
+sudo docker build -t all-hands-code-server:0.16-nikolaik .
+
+```
+
+## 修改自己的 Runtime 镜像
+```shell
+MOUNT_REPO=/home/mrh/program/openhands/OpenHands;APP_REPO=/openhands/code;dk rm -f csruntime;
+dk run --name csruntime -it -v ${MOUNT_REPO}:${MOUNT_REPO} -e MOUNT_REPO=${MOUNT_REPO} -e APP_REPO=${APP_REPO} all-hands-code-server:0.16-nikolaik bash
+cp ${MOUNT_REPO}/openhands/runtime/plugins/vscode/__init__.py ${APP_REPO}/openhands/runtime/plugins/vscode/__init__.py
+exit
+docker exec -it csruntime bash
+# 提交并覆盖
+docker commit csruntime all-hands-code-server:0.16-nikolaik
+```
+
+## code-server
+
+```shell
+# 插件路径
+file:///home/openhands/.local/share/code-server/extensions
+```

+ 2 - 4
docker-compose.yaml

@@ -4,7 +4,6 @@ services:
   openhands-app:
     image: docker.all-hands.dev/all-hands-ai/openhands:0.16
     container_name: openhands-app
-    # user: "${SANDBOX_USER_ID}:${SANDBOX_USER_ID}"
     env_file:
       - .env
     # environment:
@@ -23,10 +22,9 @@ services:
       - ${WORKSPACE_MOUNT_PATH}:${WORKSPACE_MOUNT_PATH}
       - /var/run/docker.sock:/var/run/docker.sock
       - /home/mrh/program/openhands/OpenHands/config.toml:/app/config.toml
-      - ${FILE_STORE_PATH}:/mnt/file_store
-      # - /home/mrh/program/openhands/OpenHands/openhands:/app/openhands
+      - /home/mrh/program/openhands/OpenHands/openhands/runtime/impl/eventstream/eventstream_runtime.py:/app/openhands/runtime/impl/eventstream/eventstream_runtime.py
+      # - ${FILE_STORE_PATH}:/mydata/file_store
       # - /home/mrh/program/openhands/OpenHands/openhands/core/cli.py:/app/openhands/core/cli.py
-      # - /home/mrh/program/openhands/OpenHands/openhands/agenthub/codeact_agent/codeact_agent.py:/app/openhands/agenthub/codeact_agent/codeact_agent.py
       -  /home/mrh/program/busybox-x86_64:/usr/local/bin/busybox
     extra_hosts:
       # 记得关闭防火墙,或者 sudo ufw allow from  172.0.0.0/8

+ 0 - 51
src/code-server-plugins.py

@@ -1,51 +0,0 @@
-import os
-import subprocess
-import time
-import uuid
-from dataclasses import dataclass
-
-from openhands.core.logger import openhands_logger as logger
-from openhands.runtime.plugins.requirement import Plugin, PluginRequirement
-from openhands.runtime.utils.system import check_port_available
-from openhands.utils.shutdown_listener import should_continue
-
-
-@dataclass
-class VSCodeRequirement(PluginRequirement):
-    name: str = 'vscode'
-
-
-class VSCodePlugin(Plugin):
-    name: str = 'vscode'
-
-    async def initialize(self, username: str):
-        self.vscode_port = int(os.environ['VSCODE_PORT'])
-        self.vscode_connection_token = str(uuid.uuid4())
-        assert check_port_available(self.vscode_port)
-        cmd = (
-            f"su - {username} -s /bin/bash << 'EOF'\n"
-            # f'sudo chown -R {username}:{username} /openhands/.code-server\n'
-            'cd /workspace\n'
-            f'exec code-server --bind-addr 0.0.0.0:{self.vscode_port} --auth none \n'
-            'EOF'
-        )
-        logger.debug(cmd)
-        self.gateway_process = subprocess.Popen(
-            cmd,
-            stderr=subprocess.STDOUT,
-            shell=True,
-        )
-        # read stdout until the kernel gateway is ready
-        output = ''
-        while should_continue() and self.gateway_process.stdout is not None:
-            line = self.gateway_process.stdout.readline().decode('utf-8')
-            print(line)
-            output += line
-            if 'at' in line:
-                break
-            time.sleep(1)
-            logger.debug('Waiting for VSCode server to start...')
-
-        logger.debug(
-            f'VSCode server started at port {self.vscode_port}. Output: {output}'
-        )

+ 1 - 1
src/config.toml

@@ -5,7 +5,7 @@ runtime = "eventstream"
 #runtime = "remote"
 
 # file_store="local"
-# file_store_path="/mnt/file_store"
+# file_store_path="/mydata/file_store"
 
 [sandbox]
 api_key="123"