Skip to content

Commit 19f1948

Browse files
lcolokHarold-lkk
andauthored
Optimize File System Management for Docker Launcher and Resolve class_registry Dependency Issue (#203)
* 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>
1 parent 20aeda0 commit 19f1948

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

docker/msdl/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ def main():
191191
print(t("DOCKER_LAUNCHER_COMPLETE"))
192192
except KeyboardInterrupt:
193193
print(t("KEYBOARD_INTERRUPT"))
194-
stop_and_remove_containers()
194+
# stop_and_remove_containers()
195195
sys.exit(0)
196196
except Exception as e:
197197
print(t("UNEXPECTED_ERROR", error=str(e)))
198-
stop_and_remove_containers()
198+
# stop_and_remove_containers()
199199
sys.exit(1)
200200

201201

docker/msdl/config.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,36 @@
22

33
from pathlib import Path
44

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+
527
# Get the directory where the script is located
628
PACKAGE_DIR = Path(__file__).resolve().parent
729

830
# Get the root directory of the MindSearch project
931
PROJECT_ROOT = PACKAGE_DIR.parent.parent
1032

1133
# Get the temp directory path, which is actually the working directory for executing the docker compose up command
12-
TEMP_DIR = PACKAGE_DIR / "temp"
34+
TEMP_DIR = FileSystemManager.ensure_dir(PACKAGE_DIR / "temp")
1335

1436
# Configuration file name list
1537
TEMPLATE_FILES = ["docker-compose.yaml"]
@@ -28,7 +50,7 @@
2850
REACT_DOCKERFILE = "react.dockerfile"
2951

3052
# i18n translations directory
31-
TRANSLATIONS_DIR = PACKAGE_DIR / "translations"
53+
TRANSLATIONS_DIR = FileSystemManager.ensure_dir(PACKAGE_DIR / "translations")
3254

3355
# Get the path of the .env file
34-
ENV_FILE_PATH = TEMP_DIR / ".env"
56+
ENV_FILE_PATH = FileSystemManager.ensure_file(TEMP_DIR / ".env")

docker/msdl/templates/backend/cloud_llm.dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ WORKDIR /root
88
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
99

1010
# 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-
1411
RUN pip install --no-cache-dir \
1512
duckduckgo_search==5.3.1b1 \
1613
einops \
@@ -20,7 +17,9 @@ RUN pip install --no-cache-dir \
2017
sse-starlette \
2118
termcolor \
2219
uvicorn \
23-
griffe==0.48.0
20+
griffe==0.48.0 \
21+
python-dotenv \
22+
lagent==0.2.4
2423

2524
# Copy the mindsearch folder to the /root directory of the container
2625
COPY mindsearch /root/mindsearch

docker/msdl/templates/backend/local_llm.dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ WORKDIR /root
1111
# Install Git
1212
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
1313

14-
# Copy the mindsearch folder to the /root directory of the container
15-
COPY mindsearch /root/mindsearch
16-
1714
# Install specified dependency packages
1815
# Note: lmdeploy dependency is already included in the base image, no need to reinstall
1916
RUN pip install --no-cache-dir \
2017
duckduckgo_search==5.3.1b1 \
2118
einops \
2219
fastapi \
23-
gradio \
2420
janus \
2521
pyvis \
2622
sse-starlette \
2723
termcolor \
2824
uvicorn \
29-
git+https://github.com/InternLM/lagent.git
25+
griffe==0.48.0 \
26+
python-dotenv \
27+
lagent==0.2.4
3028

31-
RUN pip install --no-cache-dir -U griffe==0.48.0
29+
# Copy the mindsearch folder to the /root directory of the container
30+
COPY mindsearch /root/mindsearch

docker/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="msdl",
5-
version="0.1.0",
5+
version="0.1.1",
66
description="MindSearch Docker Launcher",
77
packages=find_packages(),
88
python_requires=">=3.7",

0 commit comments

Comments
 (0)