Skip to content

Commit

Permalink
Optimize File System Management for Docker Launcher and Resolve class…
Browse files Browse the repository at this point in the history
…_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 <[email protected]>

* cleanup dependencies & update MSDL version & enhance UX

---------

Co-authored-by: liukuikun <[email protected]>
  • Loading branch information
lcolok and Harold-lkk authored Oct 29, 2024
1 parent 20aeda0 commit 19f1948
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docker/msdl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ def main():
print(t("DOCKER_LAUNCHER_COMPLETE"))
except KeyboardInterrupt:
print(t("KEYBOARD_INTERRUPT"))
stop_and_remove_containers()
# stop_and_remove_containers()
sys.exit(0)
except Exception as e:
print(t("UNEXPECTED_ERROR", error=str(e)))
stop_and_remove_containers()
# stop_and_remove_containers()
sys.exit(1)


Expand Down
28 changes: 25 additions & 3 deletions docker/msdl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@

from pathlib import Path


class FileSystemManager:
@staticmethod
def ensure_dir(dir_path):
"""Ensure the directory exists, create if it doesn't"""
path = Path(dir_path)
if not path.exists():
path.mkdir(parents=True, exist_ok=True)
return path

@staticmethod
def ensure_file(file_path, default_content=""):
"""Ensure the file exists, create if it doesn't"""
path = Path(file_path)
if not path.parent.exists():
FileSystemManager.ensure_dir(path.parent)
if not path.exists():
with open(path, "w") as f:
f.write(default_content)
return path


# Get the directory where the script is located
PACKAGE_DIR = Path(__file__).resolve().parent

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

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

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

# i18n translations directory
TRANSLATIONS_DIR = PACKAGE_DIR / "translations"
TRANSLATIONS_DIR = FileSystemManager.ensure_dir(PACKAGE_DIR / "translations")

# Get the path of the .env file
ENV_FILE_PATH = TEMP_DIR / ".env"
ENV_FILE_PATH = FileSystemManager.ensure_file(TEMP_DIR / ".env")
7 changes: 3 additions & 4 deletions docker/msdl/templates/backend/cloud_llm.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ WORKDIR /root
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install specified dependency packages
# Note: lmdeploy dependency is already included in the base image, no need to reinstall
RUN pip install --no-cache-dir git+https://github.com/InternLM/lagent.git

RUN pip install --no-cache-dir \
duckduckgo_search==5.3.1b1 \
einops \
Expand All @@ -20,7 +17,9 @@ RUN pip install --no-cache-dir \
sse-starlette \
termcolor \
uvicorn \
griffe==0.48.0
griffe==0.48.0 \
python-dotenv \
lagent==0.2.4

# Copy the mindsearch folder to the /root directory of the container
COPY mindsearch /root/mindsearch
11 changes: 5 additions & 6 deletions docker/msdl/templates/backend/local_llm.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ WORKDIR /root
# Install Git
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*

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

# Install specified dependency packages
# Note: lmdeploy dependency is already included in the base image, no need to reinstall
RUN pip install --no-cache-dir \
duckduckgo_search==5.3.1b1 \
einops \
fastapi \
gradio \
janus \
pyvis \
sse-starlette \
termcolor \
uvicorn \
git+https://github.com/InternLM/lagent.git
griffe==0.48.0 \
python-dotenv \
lagent==0.2.4

RUN pip install --no-cache-dir -U griffe==0.48.0
# Copy the mindsearch folder to the /root directory of the container
COPY mindsearch /root/mindsearch
2 changes: 1 addition & 1 deletion docker/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="msdl",
version="0.1.0",
version="0.1.1",
description="MindSearch Docker Launcher",
packages=find_packages(),
python_requires=">=3.7",
Expand Down

0 comments on commit 19f1948

Please sign in to comment.