lcolok liukuikun commited on
Commit
e961666
·
1 Parent(s): 4609591

Optimize File System Management for Docker Launcher and Resolve class_registry Dependency Issue (#203)

Browse files

* feat: Create TEMP_DIR if it doesn't exist

* chore: Update Docker Compose configuration and Dockerfile for MindSearch Docker launcher

* feat: Update Docker Compose configuration and Dockerfile modifying logic

* feat: Add new translations for current containers stop failure and container stopped and removed

* feat: Update Docker Compose configuration and Dockerfile for MindSearch Docker launcher

* Refactor Docker launcher's configuration setup and file handling

This commit refactors the configuration setup and file handling in the Docker launcher. It introduces a new `FileSystemManager` class with methods to ensure the existence of directories and files. The `ensure_dir` method is used to create the `temp` directory if it doesn't exist, and the `ensure_file` method is used to create the `.env` file with default content if it doesn't exist. This improves the reliability and maintainability of the Docker launcher.

* Add class_registry and python-dotenv lib

* Refactor Docker launcher's dependency installation and file handling

* Update docker/msdl/templates/backend/cloud_llm.dockerfile

Co-authored-by: liukuikun <24622904+Harold-lkk@users.noreply.github.com>

* cleanup dependencies & update MSDL version & enhance UX

---------

Co-authored-by: liukuikun <24622904+Harold-lkk@users.noreply.github.com>

docker/msdl/__main__.py CHANGED
@@ -191,11 +191,11 @@ def main():
191
  print(t("DOCKER_LAUNCHER_COMPLETE"))
192
  except KeyboardInterrupt:
193
  print(t("KEYBOARD_INTERRUPT"))
194
- stop_and_remove_containers()
195
  sys.exit(0)
196
  except Exception as e:
197
  print(t("UNEXPECTED_ERROR", error=str(e)))
198
- stop_and_remove_containers()
199
  sys.exit(1)
200
 
201
 
 
191
  print(t("DOCKER_LAUNCHER_COMPLETE"))
192
  except KeyboardInterrupt:
193
  print(t("KEYBOARD_INTERRUPT"))
194
+ # stop_and_remove_containers()
195
  sys.exit(0)
196
  except Exception as e:
197
  print(t("UNEXPECTED_ERROR", error=str(e)))
198
+ # stop_and_remove_containers()
199
  sys.exit(1)
200
 
201
 
docker/msdl/config.py CHANGED
@@ -2,6 +2,28 @@
2
 
3
  from pathlib import Path
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  # Get the directory where the script is located
6
  PACKAGE_DIR = Path(__file__).resolve().parent
7
 
@@ -9,7 +31,7 @@ PACKAGE_DIR = Path(__file__).resolve().parent
9
  PROJECT_ROOT = PACKAGE_DIR.parent.parent
10
 
11
  # Get the temp directory path, which is actually the working directory for executing the docker compose up command
12
- TEMP_DIR = PACKAGE_DIR / "temp"
13
 
14
  # Configuration file name list
15
  TEMPLATE_FILES = ["docker-compose.yaml"]
@@ -28,7 +50,7 @@ FRONTEND_DOCKERFILE_DIR = "frontend"
28
  REACT_DOCKERFILE = "react.dockerfile"
29
 
30
  # i18n translations directory
31
- TRANSLATIONS_DIR = PACKAGE_DIR / "translations"
32
 
33
  # Get the path of the .env file
34
- ENV_FILE_PATH = TEMP_DIR / ".env"
 
2
 
3
  from pathlib import Path
4
 
5
+
6
+ class FileSystemManager:
7
+ @staticmethod
8
+ def ensure_dir(dir_path):
9
+ """Ensure the directory exists, create if it doesn't"""
10
+ path = Path(dir_path)
11
+ if not path.exists():
12
+ path.mkdir(parents=True, exist_ok=True)
13
+ return path
14
+
15
+ @staticmethod
16
+ def ensure_file(file_path, default_content=""):
17
+ """Ensure the file exists, create if it doesn't"""
18
+ path = Path(file_path)
19
+ if not path.parent.exists():
20
+ FileSystemManager.ensure_dir(path.parent)
21
+ if not path.exists():
22
+ with open(path, "w") as f:
23
+ f.write(default_content)
24
+ return path
25
+
26
+
27
  # Get the directory where the script is located
28
  PACKAGE_DIR = Path(__file__).resolve().parent
29
 
 
31
  PROJECT_ROOT = PACKAGE_DIR.parent.parent
32
 
33
  # Get the temp directory path, which is actually the working directory for executing the docker compose up command
34
+ TEMP_DIR = FileSystemManager.ensure_dir(PACKAGE_DIR / "temp")
35
 
36
  # Configuration file name list
37
  TEMPLATE_FILES = ["docker-compose.yaml"]
 
50
  REACT_DOCKERFILE = "react.dockerfile"
51
 
52
  # i18n translations directory
53
+ TRANSLATIONS_DIR = FileSystemManager.ensure_dir(PACKAGE_DIR / "translations")
54
 
55
  # Get the path of the .env file
56
+ ENV_FILE_PATH = FileSystemManager.ensure_file(TEMP_DIR / ".env")
docker/msdl/templates/backend/cloud_llm.dockerfile CHANGED
@@ -8,9 +8,6 @@ WORKDIR /root
8
  RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
9
 
10
  # Install specified dependency packages
11
- # Note: lmdeploy dependency is already included in the base image, no need to reinstall
12
- RUN pip install --no-cache-dir git+https://github.com/InternLM/lagent.git
13
-
14
  RUN pip install --no-cache-dir \
15
  duckduckgo_search==5.3.1b1 \
16
  einops \
@@ -20,7 +17,9 @@ RUN pip install --no-cache-dir \
20
  sse-starlette \
21
  termcolor \
22
  uvicorn \
23
- griffe==0.48.0
 
 
24
 
25
  # Copy the mindsearch folder to the /root directory of the container
26
  COPY mindsearch /root/mindsearch
 
8
  RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
9
 
10
  # Install specified dependency packages
 
 
 
11
  RUN pip install --no-cache-dir \
12
  duckduckgo_search==5.3.1b1 \
13
  einops \
 
17
  sse-starlette \
18
  termcolor \
19
  uvicorn \
20
+ griffe==0.48.0 \
21
+ python-dotenv \
22
+ lagent==0.2.4
23
 
24
  # Copy the mindsearch folder to the /root directory of the container
25
  COPY mindsearch /root/mindsearch
docker/msdl/templates/backend/local_llm.dockerfile CHANGED
@@ -11,21 +11,20 @@ WORKDIR /root
11
  # Install Git
12
  RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
13
 
14
- # Copy the mindsearch folder to the /root directory of the container
15
- COPY mindsearch /root/mindsearch
16
-
17
  # Install specified dependency packages
18
  # Note: lmdeploy dependency is already included in the base image, no need to reinstall
19
  RUN pip install --no-cache-dir \
20
  duckduckgo_search==5.3.1b1 \
21
  einops \
22
  fastapi \
23
- gradio \
24
  janus \
25
  pyvis \
26
  sse-starlette \
27
  termcolor \
28
  uvicorn \
29
- git+https://github.com/InternLM/lagent.git
 
 
30
 
31
- RUN pip install --no-cache-dir -U griffe==0.48.0
 
 
11
  # Install Git
12
  RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
13
 
 
 
 
14
  # Install specified dependency packages
15
  # Note: lmdeploy dependency is already included in the base image, no need to reinstall
16
  RUN pip install --no-cache-dir \
17
  duckduckgo_search==5.3.1b1 \
18
  einops \
19
  fastapi \
 
20
  janus \
21
  pyvis \
22
  sse-starlette \
23
  termcolor \
24
  uvicorn \
25
+ griffe==0.48.0 \
26
+ python-dotenv \
27
+ lagent==0.2.4
28
 
29
+ # Copy the mindsearch folder to the /root directory of the container
30
+ COPY mindsearch /root/mindsearch
docker/setup.py CHANGED
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
 
3
  setup(
4
  name="msdl",
5
- version="0.1.0",
6
  description="MindSearch Docker Launcher",
7
  packages=find_packages(),
8
  python_requires=">=3.7",
 
2
 
3
  setup(
4
  name="msdl",
5
+ version="0.1.1",
6
  description="MindSearch Docker Launcher",
7
  packages=find_packages(),
8
  python_requires=">=3.7",