diff --git a/oedp/src/commands/run/run_action.py b/oedp/src/commands/run/run_action.py index fddf7209fbb52615bddadc0512ba507c3bb2a1c2..356aa5d2ee802054a9e379e693be89e7ebe4fb02 100644 --- a/oedp/src/commands/run/run_action.py +++ b/oedp/src/commands/run/run_action.py @@ -18,17 +18,19 @@ from src.utils.log.logger_generator import LoggerGenerator class RunAction: - def __init__(self, project: str, action: str, tasks: list): + def __init__(self, action: str, tasks: list, project: str, debug: bool): """ 执行指定项目的指定方法。 :param project: 项目目录路径 :param action: 方法名称 :param tasks: 方法代码路径 + :param debug: 是否启用调试模式 """ - self.project = project self.action = action self.tasks = tasks + self.project = project + self.debug = debug self.log = LoggerGenerator().get_logger('run_action') def run(self) -> bool: @@ -55,14 +57,14 @@ class RunAction: return True def _run_playbook(self, task: dict, project: str) -> bool: - if 'disabled' in task and task['disabled'] == True: - self.log.info(f'Skipping task {task.get("name", "")}') + if self.debug and task.get('disabled_in_debug', False): + self.log.info(f'Skipping task "{task.get("name", "unamed task")}"') return True self.log.info(f'Running task {task.get("name", "")}') workspace = os.path.join(project, 'workspace') playbook = os.path.join(workspace, task['playbook']) if not os.path.exists(playbook): - self.log.error(f'Playbook {playbook} does not exist') + self.log.error(f'Playbook does not exist: {os.path.abspath(playbook)}') return False inventory = os.path.join(project, 'config.yaml') cmd = ['ansible-playbook', playbook, '-i', inventory] @@ -75,12 +77,13 @@ class RunAction: if 'scope' in task and task['scope'] != 'all': cmd.extend(['--limit', task['scope']]) self.log.debug(f'Executing cmd: {cmd}') - out, err, ret = CommandExecutor.run_single_cmd(cmd, print_on_console=True) - if ret: - if err: - self.log.error(f'Execute cmd failed: {err}') - else: - self.log.error(f'Execute cmd failed') + try: + out, err, ret = CommandExecutor.run_single_cmd(cmd, print_on_console=True) + if ret != 0: + self.log.error(f'Execute cmd failed [code:{ret}]:\nSTDOUT: {out}\nSTDERR: {err}') + return False + except Exception as e: + self.log.error(f'Exception occurred: {str(e)}') return False - self.log.info(f'Execute succeeded') + self.log.info(f'Execute succeeded: {task.get("name", "unamed task")}') return True diff --git a/oedp/src/commands/run/run_cmd.py b/oedp/src/commands/run/run_cmd.py index b839138e6664254cf59eb412eaa2e804af0c60b0..46b6640f905f7bebe3c018e2dfdc428b5b718215 100644 --- a/oedp/src/commands/run/run_cmd.py +++ b/oedp/src/commands/run/run_cmd.py @@ -21,15 +21,17 @@ from decimal import Decimal class RunCmd: - def __init__(self, action: str, project: str): + def __init__(self, action: str, project: str, debug: bool): """ 执行一个项目中的方法。 :param action: 方法名称 :param project: 项目目录路径 + :param debug: 是否启用调试模式 """ self.action = action self.project = project + self.debug = debug self.log = LoggerGenerator().get_logger('run_cmd') def run(self): @@ -52,7 +54,7 @@ class RunCmd: self.log.error(f'Failed to get tasks info: {action}') return False tasks = action['tasks'] - return RunAction(self.project, self.action, tasks).run() + return RunAction(self.action, tasks, self.project, self.debug).run() finally: end_time = time.time() seconds = Decimal(f"{format(end_time - start_time, '.1f')}") diff --git a/oedp/src/parsers/oedp_parser.py b/oedp/src/parsers/oedp_parser.py index dd0396e38eeb90ade8c4294742cdda6f05daf1d8..3e40a7cc1eec7b12d90f7e45baf6f202d7c624f2 100644 --- a/oedp/src/parsers/oedp_parser.py +++ b/oedp/src/parsers/oedp_parser.py @@ -169,6 +169,11 @@ class OeDeployParser: default=os.getcwd(), help='Specify the project path' ) + deploy_command.add_argument( + '-d', '--debug', + action='store_true', + help='Enable debug mode' + ) deploy_command.set_defaults(func=self._run_run_command) def _add_check_command(self): @@ -219,7 +224,8 @@ class OeDeployParser: def _run_run_command(args): action = args.action project = args.project - return RunCmd(action, project).run() + debug = args.debug + return RunCmd(action, project, debug).run() @staticmethod def _run_check_command(args): diff --git a/plugins/deepseek-r1/main.yaml b/plugins/deepseek-r1/main.yaml index cbc65e08553832cb63b9200041c439fe2d600684..1df3c13cd87ce1acd56255e1bef5a41a184153cb 100644 --- a/plugins/deepseek-r1/main.yaml +++ b/plugins/deepseek-r1/main.yaml @@ -5,7 +5,19 @@ action: install: description: install DeepSeek-R1 tasks: - - name: install DeepSeek-R1 - playbook: install.yaml + - name: env prepare + playbook: 0-env_prepare.yaml + scope: all + disabled_in_debug: true + - name: install ollama + playbook: 1-install_ollama.yaml + scope: all + disabled_in_debug: true + - name: modify modelfile + playbook: 2-modify_modelfile.yaml + scope: all + disabled_in_debug: false + - name: start DeepSeek-R1 + playbook: 3-start_deepseek.yaml scope: all \ No newline at end of file diff --git a/plugins/deepseek-r1/workspace/0-env_prepare.yaml b/plugins/deepseek-r1/workspace/0-env_prepare.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c3c41456ca45f51a6e92d22d5244e86c950e4601 --- /dev/null +++ b/plugins/deepseek-r1/workspace/0-env_prepare.yaml @@ -0,0 +1,14 @@ +--- +- name: Install Ollama and run Deepseek + hosts: all + + tasks: + - name: Ensure SELinux Python bindings are installed + yum: + name: python3-libselinux + state: present + + - name: Ensure tar is installed + yum: + name: tar + state: present diff --git a/plugins/deepseek-r1/workspace/install.yaml b/plugins/deepseek-r1/workspace/1-install_ollama.yaml similarity index 50% rename from plugins/deepseek-r1/workspace/install.yaml rename to plugins/deepseek-r1/workspace/1-install_ollama.yaml index 52e322ad77d1d30b07d3c31d78d278729d03881b..506bd9143697070e4804b842123b2c3d5a5171c2 100644 --- a/plugins/deepseek-r1/workspace/install.yaml +++ b/plugins/deepseek-r1/workspace/1-install_ollama.yaml @@ -3,10 +3,8 @@ hosts: all vars: ollama_file: "{{ ollama_download | basename }}" - modelfile_file: "{{ modelfile_download | basename }}" tasks: - # ================ start ollama ===================== - name: Ensure SELinux Python bindings are installed yum: @@ -79,7 +77,7 @@ changed_when: false ignore_errors: no - - name: Create ollama system user and group + - name: Create ollama system user and group block: - name: Ensure ollama group exists group: @@ -121,87 +119,3 @@ systemd: name: ollama state: started - - # ================ modify modelfile ===================== - - - name: Download modelfile - block: - - name: Ensure modelfile download path exists - file: - path: "{{ modelfile_download_path }}" - state: directory - mode: '0755' - - - name: Copy download.sh to remote - copy: - src: download.sh - dest: "{{ modelfile_download_path }}/download.sh" - owner: root - group: root - mode: '0644' - - - name: Execute download.sh - shell: > - bash {{ modelfile_download_path }}/download.sh - {{ modelfile_download }} - {{ modelfile_download_path }} - {{ 1 if download_checksum else 0 }} - {{ download_timeout }} - {{ download_retry }} - >> {{ modelfile_download_path }}/download.log - ignore_errors: no - async: 0 - register: download_result - failed_when: download_result.rc != 0 - - rescue: - - name: Print error message of downloading modelfile - debug: - msg: "Unable to download modelfile, parameter tuning will not take effect." - - - name: Print manual execution message - debug: - msg: "Please manually execute: ollama run deepseek-r1:{{ deepseek_version }}" - - - name: Mark playbook as successful - meta: end_play - - - name: Copy Modelfile to destination - copy: - src: Modelfile - dest: "{{ modelfile_download_path }}/Modelfile" - owner: root - group: root - mode: '0644' - - - name: Modify Modelfile parameters - lineinfile: - path: "{{ modelfile_download_path }}/Modelfile" - regexp: "{{ item.regexp }}" - line: "{{ item.line }}" - backrefs: yes - loop: - - { regexp: '^FROM .*$', line: 'FROM {{ modelfile_download_path }}/{{ modelfile_file }}' } - - { regexp: '^PARAMETER temperature .*$', line: 'PARAMETER temperature {{ parameter.temperature }}' } - - { regexp: '^PARAMETER top_p .*$', line: 'PARAMETER top_p {{ parameter.top_p }}' } - - { regexp: '^PARAMETER top_k .*$', line: 'PARAMETER top_k {{ parameter.top_k }}' } - - { regexp: '^PARAMETER num_ctx .*$', line: 'PARAMETER num_ctx {{ parameter.num_ctx }}' } - - { regexp: '^PARAMETER num_thread .*$', line: 'PARAMETER num_thread {{ parameter.num_thread }}' } - - { regexp: '^PARAMETER num_gpu .*$', line: 'PARAMETER num_gpu {{ parameter.num_gpu }}' } - - - name: Verify Modelfile content - shell: cat "{{ modelfile_download_path }}/Modelfile" - register: modelfile_content - - - name: Display modified Modelfile content - debug: - msg: "{{ modelfile_content.stdout }}" - - # ================ start deepseek ===================== - - - name: Create Deepseek - command: ollama create -f {{ modelfile_download_path }}/Modelfile deepseek-r1:{{ deepseek_version }} - - - name: Print manual execution message after success - debug: - msg: "Please manually execute: ollama run deepseek-r1:{{ deepseek_version }}" diff --git a/plugins/deepseek-r1/workspace/2-modify_modelfile.yaml b/plugins/deepseek-r1/workspace/2-modify_modelfile.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1c8e8bca8f976f9e49f976b2ab65d9dd1bf6ccc5 --- /dev/null +++ b/plugins/deepseek-r1/workspace/2-modify_modelfile.yaml @@ -0,0 +1,79 @@ +--- +- name: Install Ollama and run Deepseek + hosts: all + vars: + modelfile_file: "{{ modelfile_download | basename }}" + + tasks: + - name: Download modelfile + block: + - name: Ensure modelfile download path exists + file: + path: "{{ modelfile_download_path }}" + state: directory + mode: '0755' + + - name: Copy download.sh to remote + copy: + src: download.sh + dest: "{{ modelfile_download_path }}/download.sh" + owner: root + group: root + mode: '0644' + + - name: Execute download.sh + shell: > + bash {{ modelfile_download_path }}/download.sh + {{ modelfile_download }} + {{ modelfile_download_path }} + {{ 1 if download_checksum else 0 }} + {{ download_timeout }} + {{ download_retry }} + >> {{ modelfile_download_path }}/download.log + ignore_errors: no + async: 0 + register: download_result + failed_when: download_result.rc != 0 + + rescue: + - name: Print error message of downloading modelfile + debug: + msg: "Unable to download modelfile, parameter tuning will not take effect." + + - name: Print manual execution message + debug: + msg: "Please manually execute: ollama run deepseek-r1:{{ deepseek_version }}" + + - name: Mark playbook as successful + meta: end_play + + - name: Copy Modelfile to destination + copy: + src: Modelfile + dest: "{{ modelfile_download_path }}/Modelfile" + owner: root + group: root + mode: '0644' + + - name: Modify Modelfile parameters + lineinfile: + path: "{{ modelfile_download_path }}/Modelfile" + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + backrefs: yes + loop: + - { regexp: '^FROM .*$', line: 'FROM {{ modelfile_download_path }}/{{ modelfile_file }}' } + - { regexp: '^PARAMETER temperature .*$', line: 'PARAMETER temperature {{ parameter.temperature }}' } + - { regexp: '^PARAMETER top_p .*$', line: 'PARAMETER top_p {{ parameter.top_p }}' } + - { regexp: '^PARAMETER top_k .*$', line: 'PARAMETER top_k {{ parameter.top_k }}' } + - { regexp: '^PARAMETER num_ctx .*$', line: 'PARAMETER num_ctx {{ parameter.num_ctx }}' } + - { regexp: '^PARAMETER num_thread .*$', line: 'PARAMETER num_thread {{ parameter.num_thread }}' } + - { regexp: '^PARAMETER num_gpu .*$', line: 'PARAMETER num_gpu {{ parameter.num_gpu }}' } + + - name: Verify Modelfile content + shell: cat "{{ modelfile_download_path }}/Modelfile" + register: modelfile_content + + - name: Display modified Modelfile content + debug: + msg: "{{ modelfile_content.stdout }}" diff --git a/plugins/deepseek-r1/workspace/3-start_deepseek.yaml b/plugins/deepseek-r1/workspace/3-start_deepseek.yaml new file mode 100644 index 0000000000000000000000000000000000000000..014c3814fd430a20ac44a9dbdbe856f27cc492df --- /dev/null +++ b/plugins/deepseek-r1/workspace/3-start_deepseek.yaml @@ -0,0 +1,11 @@ +--- +- name: Install Ollama and run Deepseek + hosts: all + + tasks: + - name: Create Deepseek + command: ollama create -f {{ modelfile_download_path }}/Modelfile deepseek-r1:{{ deepseek_version }} + + - name: Print manual execution message after success + debug: + msg: "Please manually execute: ollama run deepseek-r1:{{ deepseek_version }}"